home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / TELECOM / UUCPbb_2_1_src.lzh / UUCPBB21 / getseq.c < prev    next >
Text File  |  1994-09-25  |  2KB  |  72 lines

  1. /*  getseq.c   The routine returns a unique sequence number as a type long.
  2.     Copyright (C) 1990, 1993  Rick Adams and Bob Billson
  3.  
  4.     This file is part of the OS-9 UUCP package, UUCPbb.
  5.  
  6.     This program is free software; you can redistribute it and/or modify
  7.     it under the terms of the GNU General Public License as published by
  8.     the Free Software Foundation; either version 2 of the License, or
  9.     (at your option) any later version.
  10.  
  11.     This program is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.     GNU General Public License for more details.
  15.  
  16.     You should have received a copy of the GNU General Public License
  17.     along with this program; if not, write to the Free Software
  18.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  
  20.     The author of UUCPbb, Bob Billson, can be contacted at:
  21.     bob@kc2wz.bubble.org  or  uunet!kc2wz!bob  or  by snail mail:
  22.     21 Bates Way, Westfield, NJ 07090
  23. */
  24.  
  25. #include "uucp.h"
  26. #include <modes.h>
  27.  
  28. EXTERN QQ unsigned myuid;
  29.  
  30.  
  31. long getseq (seqfile)
  32. char *seqfile;
  33. {
  34.      char tmpstr[7];
  35.      FILE *file;
  36.      long sequence, atol();
  37.  
  38.      /* become superuser */
  39.      asetuid (0);
  40.  
  41.      /* update sequence number */
  42.      if ((file = fopen (seqfile, "r")) == NULL)
  43.        {
  44.           if ((file = fopen (seqfile, "w")) == NULL)
  45.                fatal ("getseq() can't open sequence file for read or create");
  46.  
  47.           fputs ("1\n", file);
  48.           sequence = 1;
  49.        }
  50.      else
  51.        {
  52.           mfgets (tmpstr, sizeof (tmpstr), file);
  53.           fclose (file);
  54.           sequence = atol (tmpstr) + 1;
  55.  
  56.           /* if sequence reachs 100,000, wrap back to 1 */
  57.           if (sequence > 99999)
  58.                sequence = 1;
  59.  
  60.           if ((file = fopen (seqfile, "w")) == NULL)
  61.                fatal ("getseq() can't open sequence file for write");
  62.  
  63.           fprintf (file, "%ld\n", sequence);
  64.        }
  65.  
  66.      /* protect sequence file */
  67.      fixperms (file);
  68.      asetuid (myuid);
  69.      fclose (file);
  70.      return (sequence);
  71. }
  72.