Annotation of researchv10no/libc/gen/openshares.c, revision 1.1.1.1

1.1       root        1: /*LINTLIBRARY*/
                      2: 
                      3: /*
                      4: **     Open ``shares'' file and optionally lock it.
                      5: */ 
                      6: 
                      7: #include       <shares.h>
                      8: #include       <sys/filio.h>
                      9: #include       <errno.h>
                     10: #include       <libc.h>
                     11: 
                     12: 
                     13: int            ShareFd;
                     14: static char *  ShareFile       = SHAREFILE;
                     15: static int     ShareOpen;
                     16: 
                     17: 
                     18: 
                     19: int
                     20: openshares(lock)
                     21:        int     lock;   /* True if writing desired */
                     22: {
                     23:        if ( ShareOpen )
                     24:                return 1;
                     25: 
                     26:        if ( (ShareFd = open(ShareFile, 2)) == SYSERROR )
                     27:        {
                     28:                if ( !lock && (errno == EACCES) )
                     29:                {
                     30:                        if ( (ShareFd = open(ShareFile, 0)) == SYSERROR )
                     31:                                return 0;
                     32:                }
                     33:                else
                     34:                        return 0;
                     35:        }
                     36: 
                     37: #      ifdef   FIOCLEX
                     38:        (void)ioctl(ShareFd, FIOCLEX, 0);       /* close on exec */
                     39: #      endif
                     40: 
                     41:        ShareOpen = 1;
                     42:        errno = 0;
                     43: 
                     44:        return 1;
                     45: }
                     46: 
                     47: 
                     48: void
                     49: closeshares()
                     50: {
                     51:        if ( !ShareOpen )
                     52:                return;
                     53: 
                     54:        (void)close(ShareFd);
                     55: 
                     56:        ShareOpen = 0;
                     57: }
                     58: 
                     59: 
                     60: void
                     61: sharesfile(file)
                     62:        char *  file;
                     63: {
                     64:        closeshares();
                     65:        ShareFile = file;
                     66: }

unix.superglobalmegacorp.com

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