Annotation of researchv10no/cmd/uucp/gnxseq.c, revision 1.1

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

unix.superglobalmegacorp.com

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