Commit | Line | Data |
---|---|---|
808bd6eb N |
1 | #include "uucp.h" |
2 | ||
3 | ||
4 | /******* | |
5 | * gename(pre, sys, grade, file) generate file name | |
6 | * char grade, *sys, pre, *file; | |
7 | * | |
8 | * return codes: none | |
9 | */ | |
10 | ||
11 | gename(pre, sys, grade, file) | |
12 | char pre, *sys, grade, *file; | |
13 | { | |
14 | char sqnum[5]; | |
15 | ||
16 | getseq(sqnum); | |
17 | sprintf(file, "%c.%.7s%c%.4s", pre, sys, grade, sqnum); | |
18 | DEBUG(4, "file - %s\n", file); | |
19 | return; | |
20 | } | |
21 | ||
22 | ||
23 | #define SLOCKTIME 10L | |
24 | #define SLOCKTRIES 5 | |
25 | #define SEQLEN 4 | |
26 | ||
27 | /******* | |
28 | * getseq(snum) get next sequence number | |
29 | * char *snum; | |
30 | * | |
31 | * return codes: none | |
32 | */ | |
33 | ||
34 | getseq(snum) | |
35 | char *snum; | |
36 | { | |
37 | FILE *fp; | |
38 | int n; | |
39 | ||
40 | for (n = 0; n < SLOCKTRIES; n++) { | |
41 | if (!ulockf( SEQLOCK, SLOCKTIME)) | |
42 | break; | |
43 | sleep(5); | |
44 | } | |
45 | ||
46 | ASSERT(n < SLOCKTRIES, "CAN NOT GET %s", SEQLOCK); | |
47 | ||
48 | if ((fp = fopen(SEQFILE, "r")) != NULL) { | |
49 | /* read sequence number file */ | |
50 | fscanf(fp, "%4d", &n); | |
51 | fp = freopen(SEQFILE, "w", fp); | |
52 | ASSERT(fp != NULL, "CAN NOT OPEN %s", SEQFILE); | |
53 | chmod(SEQFILE, 0666); | |
54 | } | |
55 | else { | |
56 | /* can not read file - create a new one */ | |
57 | if ((fp = fopen(SEQFILE, "w")) == NULL) | |
58 | /* can not write new seqeunce file */ | |
59 | return(FAIL); | |
60 | chmod(SEQFILE, 0666); | |
61 | n = 0; | |
62 | } | |
63 | ||
64 | fprintf(fp, "%s", sprintf(snum, "%04d", ++n)); | |
65 | fclose(fp); | |
66 | rmlock(SEQLOCK); | |
67 | return(0); | |
68 | } |