
/*
 *  SEQ.C
 *
 *  (C) Copyright 1989-1990 by Matthew Dillon,  All Rights Reserved.
 *
 *  Returns a unique sequence number
 */

#include <stdio.h>

GetSequence(bump)
{
    char *seqfile = "UULIB:seq";
    FILE *fp;
    int seq;
    char buf[32];

    LockFile(seqfile);
    fp = fopen("UULIB:seq","r");
    if (fp) {
	fgets(buf, 32, fp);
	seq = atoi(buf);
	fclose(fp);
    } else {
	perror("UULIB:seq");
	seq = -1;
    }

    if (seq > 0) {
	fp = fopen("UULIB:seq", "w");
	if (fp) {
	    fprintf(fp,"%d", seq + bump);
	    fclose(fp);
	} else {
	    perror("UULIB:seq");
	    seq = -1;
	}
    }
    UnLockFile(seqfile);
    return(seq);
}

