Changeset 688


Ignore:
Timestamp:
Sep 11, 2003, 3:16:25 AM (22 years ago)
Author:
bird
Message:

#634: Implemented flock() using fcntl().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/emx/src/lib/io/flock.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r687 r688  
    22
    33#include "libc-alias.h"
    4 #include <sys/file.h>
     4#include <io.h>
     5#include <sys/fcntl.h>
     6#include <limits.h>
    57#include <errno.h>
    68#include <emx/io.h>
    79
    8 int _STD(flock) (int handle, int operation)
     10/** @todo update limit.h to FreeBSD 5.1 or later. */
     11#ifndef OFF_MAX
     12#define OFF_MAX LONG_MAX
     13#endif
     14
     15/** @todo check that fcntl is ok for flock implementation, have seen
     16 * comments and #defines in both Linux and FreeBSD which hints that
     17 * this isn't exactly the same thing.
     18 * @todo check thread safety as I see FreeBSD is taking that into account.
     19 */
     20int _STD(flock) (int fd, int request)
    921{
    10   if (_fd_flags (handle) == NULL)
     22  struct flock  flck;
     23  int           fcntl_request;
     24
     25  /* init the struct with defaults */
     26  flck.l_start = 0;
     27  flck.l_len = OFF_MAX;
     28  flck.l_whence = SEEK_SET;
     29  flck.l_pid = 0;
     30  if (request & LOCK_NB)
     31    fcntl_request = F_SETLK;            /* don't block when locking */
     32  else
     33    fcntl_request = F_SETLKW;
     34
     35  /* what to do */
     36  switch (request & (LOCK_SH | LOCK_EX | LOCK_UN))
    1137    {
    12       errno = EBADF;
    13       return -1;
     38      /* shared file lock */
     39      case LOCK_SH:
     40          flck.l_type = F_RDLCK;
     41          break;
     42      /* exclusive file lock */
     43      case LOCK_EX:
     44          flck.l_type = F_WRLCK;
     45          break;
     46
     47      /* unlock file */
     48      case LOCK_UN:
     49          flck.l_type = F_UNLCK;
     50          fcntl_request = F_SETLK;      /* doesn't hurt I think? */
     51          break;
     52
     53      default:
     54          errno = EINVAL;
     55          return -1;
    1456    }
    15   /*...this is a dummy function...*/
    16   return 0;
     57
     58  /* do work */
     59  return fcntl(fd, fcntl_request, &flck);
    1760}
     61
Note: See TracChangeset for help on using the changeset viewer.