[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]

Re: [ID 20000125.002] Problem in documentation of Fcntl constants



From pp_sys.c:

    #  ifdef FLOCK
	 static int FLOCK (int, int);

	/*
	 * These are the flock() constants.  Since this sytems doesn't have
	 * flock(), the values of the constants are probably not available.
	 */
    #    ifndef LOCK_SH
    #      define LOCK_SH 1
    #    endif
    #    ifndef LOCK_EX
    #      define LOCK_EX 2
    #    endif
    #    ifndef LOCK_NB
    #      define LOCK_NB 4
    #    endif
    #    ifndef LOCK_UN
    #      define LOCK_UN 8
    #    endif
    #  endif /* emulating flock() */

    #endif /* no flock() */

    fcntl_emulate_flock(int fd, int operation)
    {
	struct flock flock;
     
	switch (operation & ~LOCK_NB) {
	case LOCK_SH:
	    flock.l_type = F_RDLCK;
	    break;
	case LOCK_EX:
	    flock.l_type = F_WRLCK;
	    break;
	case LOCK_UN:
	    flock.l_type = F_UNLCK;
	    break;
	default:
	    errno = EINVAL;
	    return -1;
	}
	flock.l_whence = SEEK_SET;
	flock.l_start = flock.l_len = (Off_t)0;
     
	return fcntl(fd, (operation & LOCK_NB) ? F_SETLK : F_SETLKW, &flock);
    }

The values of LOCK_?? are "famous".   People pass in 6, and expect it to
mean FLOCK_EX|FLOCK_NB.  In fact, you'll break programs if you don't do
this.

--tom


[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]