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