home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 4 / CDPD_IV.bin / networking / uucp / amigauucpsrc / lib / seq.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-29  |  807 b   |  53 lines

  1.  
  2. /*
  3.  *  SEQ.C
  4.  *
  5.  *  (C) Copyright 1989-1990 by Matthew Dillon,  All Rights Reserved.
  6.  *
  7.  *  Returns a unique sequence number
  8.  */
  9.  
  10. #include <stdio.h>
  11. #include "config.h"
  12.  
  13. Prototype int GetSequence(int);
  14.  
  15. int
  16. GetSequence(bump)
  17. int bump;
  18. {
  19.     char *seqLockFile = "seq";
  20.     FILE *fp;
  21.     char *fileName = MakeConfigPath(UULIB, "seq");
  22.     int seq;
  23.     char buf[32];
  24.  
  25.     LockFile(seqLockFile);
  26.     fp = fopen(fileName, "r");
  27.     if (fp) {
  28.     fgets(buf, 32, fp);
  29.     seq = atoi(buf);
  30.     fclose(fp);
  31.     } else {
  32.     perror(fileName);
  33.     seq = -1;
  34.     }
  35.  
  36.     if (bump && seq >= 0) {
  37.     if (bump + seq > 0xFFFFF)
  38.         seq = 1;
  39.  
  40.     fp = fopen(fileName, "w");
  41.     if (fp) {
  42.         fprintf(fp,"%d", seq + bump);
  43.         fclose(fp);
  44.     } else {
  45.         perror(fileName);
  46.         seq = -1;
  47.     }
  48.     }
  49.     UnLockFile(seqLockFile);
  50.     return(seq);
  51. }
  52.  
  53.