8349 thrd_equal implements the wrong specification
[unleashed.git] / usr / src / cmd / bnu / gnxseq.c
blobda9656b090fa51c352604269f6a3b136d8b2e072
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
22 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
23 /* All Rights Reserved */
25 #include "uucp.h"
28 * get next conversation sequence number
29 * rmtname -> name of remote system
30 * returns:
31 * 0 -> no entery
32 * 1 -> 0 sequence number
34 int
35 gnxseq(char *rmtname)
37 register FILE *fp0, *fp1;
38 register struct tm *tp;
39 int count = 0, ct, ret;
40 char buf[BUFSIZ], name[NAMESIZE];
41 time_t clock;
43 if (access(SQFILE, 0) != 0)
44 return (0);
47 int i;
48 for (i = 0; i < 5; i++)
49 if ((ret = mklock(SQLOCK)) == SUCCESS)
50 break;
51 sleep(5);
53 if (ret != SUCCESS) {
54 logent("CAN'T LOCK", SQLOCK);
55 DEBUG(4, "can't lock %s\n", SQLOCK);
56 return (0);
58 if ((fp0 = fopen(SQFILE, "r")) == NULL)
59 return (0);
60 if ((fp1 = fopen(SQTMP, "w")) == NULL) {
61 fclose(fp0);
62 return (0);
64 chmod(SQTMP, DFILEMODE);
66 while (fgets(buf, BUFSIZ, fp0) != NULL) {
67 ret = sscanf(buf, "%s%d", name, &ct);
68 if (ret < 2)
69 ct = 0;
70 name[7] = '\0';
71 if (ct > 9998)
72 ct = 0;
73 if (strncmp(rmtname, name, SYSNSIZE) != SAME) {
74 fputs(buf, fp1);
75 continue;
79 * found name
81 count = ++ct;
82 time(&clock);
83 tp = localtime(&clock);
84 fprintf(fp1, "%s %d %d/%d-%d:%2.2d\n", name, ct,
85 tp->tm_mon + 1, tp->tm_mday, tp->tm_hour,
86 tp->tm_min);
89 * write should be checked
91 while (fgets(buf, BUFSIZ, fp0) != NULL)
92 fputs(buf, fp1);
94 fclose(fp0);
95 fclose(fp1);
96 if (count == 0) {
97 rmlock(SQLOCK);
98 unlink(SQTMP);
100 return (count);
104 * commit sequence update
105 * returns:
106 * 0 -> ok
107 * other -> link failed
110 cmtseq(void)
112 int ret;
114 if ((ret = access(SQTMP, 0)) != 0) {
115 rmlock(SQLOCK);
116 return (0);
118 unlink(SQFILE);
119 ret = link(SQTMP, SQFILE);
120 unlink(SQTMP);
121 rmlock(SQLOCK);
122 return (ret);
126 * unlock sequence file
128 void
129 ulkseq(void)
131 unlink(SQTMP);
132 rmlock(SQLOCK);