1: #ifndef lint
   2: static char sccsid[] = "@(#)gnxseq.c	5.2 (Berkeley) 7/2/83";
   3: #endif
   4: 
   5: #include "uucp.h"
   6: #include <sys/types.h>
   7: #include <sys/time.h>
   8: 
   9: extern  time_t  time();
  10: 
  11: /*******
  12:  *	gnxseq(rmtname)		get next conversation sequence number
  13:  *	char *rmtname;
  14:  *
  15:  *	return - 0 no entry | >0 sequence number
  16:  */
  17: 
  18: gnxseq(rmtname)
  19: char *rmtname;
  20: {
  21:     int count = 0, ct, ret, i;
  22:     register struct tm *tp;
  23:     extern struct tm *localtime();
  24:     time_t clock;
  25:     register FILE *fp0, *fp1;
  26:     char buf[BUFSIZ], name[NAMESIZE];
  27: 
  28:     if (access(SQFILE, 0) != 0) /* nothing to do here */
  29:         return(0);
  30: 
  31:     for (i = 0; i < 5; i++) {
  32:         if ((ret = ulockf(SQLOCK, (time_t)  SQTIME)) == 0)
  33:             break;
  34:         sleep(5);
  35:     }
  36:     if (ret != 0) {
  37:         logent("CAN'T LOCK", SQLOCK);
  38:         DEBUG(4, "can't lock %s\n", SQLOCK);
  39:         return(0);
  40:     }
  41:     if ((fp0 = fopen(SQFILE, "r")) == NULL)
  42:         return(0);
  43:     if ((fp1 = fopen(SQTMP, "w")) == NULL) {
  44:         fclose(fp0);
  45:         return(0);
  46:     }
  47:     chmod(SQTMP, 0400);
  48: 
  49:     while (fgets(buf, BUFSIZ, fp0) != NULL) {
  50:         ret = sscanf(buf, "%s%d", name, &ct);
  51:         if (ret < 2)
  52:             ct = 0;
  53:         name[7] = '\0';
  54:         if (ct > 9998)
  55:             ct = 0;
  56:         if (strcmp(rmtname, name) != SAME) {
  57:             fputs(buf, fp1);
  58:             continue;
  59:         }
  60: 
  61:         /*  found name  */
  62:         count = ++ct;
  63:         time(&clock);
  64:         tp = localtime(&clock);
  65:         fprintf(fp1, "%s %d %d/%d-%d:%02d\n", name, ct,
  66:           tp->tm_mon + 1, tp->tm_mday, tp->tm_hour,
  67:           tp->tm_min);
  68:         while (fgets(buf, BUFSIZ, fp0) != NULL)
  69:             fputs(buf, fp1);
  70:     }
  71:     fclose(fp0);
  72:     fclose(fp1);
  73:     if (count == 0) {
  74:         rmlock(SQLOCK);
  75:         unlink(SQTMP);
  76:     }
  77:     return(count);
  78: }
  79: 
  80: 
  81: /***
  82:  *	cmtseq()	commit sequence update
  83:  *
  84:  *	return  0  ok | other - link failed
  85:  */
  86: 
  87: cmtseq()
  88: {
  89:     register int ret;
  90: 
  91:     if ((ret = access(SQTMP, 0400)) != 0) {
  92:         rmlock(SQLOCK);
  93:         return(0);
  94:     }
  95:     unlink(SQFILE);
  96:     ret = link(SQTMP, SQFILE);
  97:     unlink(SQTMP);
  98:     rmlock(SQLOCK);
  99:     return(ret);
 100: }
 101: 
 102: /***
 103:  *	ulkseq()	unlock sequence file
 104:  */
 105: 
 106: ulkseq()
 107: {
 108:     unlink(SQTMP);
 109:     rmlock(SQLOCK);
 110: }

Defined functions

cmtseq defined in line 87; used 2 times
gnxseq defined in line 18; used 2 times
ulkseq defined in line 106; used 4 times

Defined variables

sccsid defined in line 2; never used
Last modified: 1983-07-03
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 804
Valid CSS Valid XHTML 1.0 Strict