Annotation of 41BSD/cmd/uucp/gnxseq.c, revision 1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.