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

unix.superglobalmegacorp.com

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