Annotation of coherent/b/lib/libc/gen/lockf.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * libc/gen/lockf.c
                      3:  * File locking.
                      4:  */
                      5: 
                      6: #include <fcntl.h>
                      7: #include <unistd.h>
                      8: #include <errno.h>
                      9: 
                     10: lockf(fd, cmd, size) register int fd, cmd; long size;
                     11: {
                     12:        struct flock fl;
                     13:        register int fcmd;
                     14: 
                     15:        fl.l_type = F_WRLCK;
                     16:        fl.l_whence = SEEK_CUR;
                     17:        fl.l_start = 0;
                     18:        fl.l_len = size;
                     19: 
                     20:        switch (cmd) {
                     21: 
                     22:        case F_ULOCK:
                     23:                fl.l_type = F_UNLCK;
                     24:                /* fall through... */
                     25: 
                     26:        case F_TLOCK:
                     27:                fcmd = F_SETLK;
                     28: lab:
                     29:                if (fcntl(fd, fcmd, &fl) == -1) {
                     30:                        if (errno == ENOLCK)
                     31:                                errno = EDEADLK;
                     32:                        return -1;
                     33:                }
                     34:                break;
                     35: 
                     36:        case F_LOCK:
                     37:                fcmd = F_SETLKW;
                     38:                goto lab;
                     39:                break;
                     40: 
                     41:        case F_TEST:
                     42:                if (fcntl(fd, F_GETLK, &fl) == -1)
                     43:                        return -1;
                     44:                if (fl.l_type != F_UNLCK) {
                     45:                        errno = EAGAIN;
                     46:                        return -1;
                     47:                }
                     48:                break;
                     49: 
                     50:        default:
                     51:                errno = EINVAL;
                     52:                return -1;
                     53: 
                     54:        }
                     55:        return 0;
                     56: }
                     57: 
                     58: /* end of lockf.c */

unix.superglobalmegacorp.com

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