home *** CD-ROM | disk | FTP | other *** search
/ back2roots/padua / padua.7z / padua / uucp / duucp-1.17 / AU-117b4-src.lha / src / lib / seq.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-24  |  811 b   |  59 lines

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