Back to index

php5  5.3.10
Functions
flock.c File Reference
#include "php.h"
#include <windows.h>
#include <io.h>
#include <errno.h>
#include "flock.h"

Go to the source code of this file.

Functions

PHPAPI int flock (int fd, int op)

Function Documentation

PHPAPI int flock ( int  fd,
int  op 
)

Definition at line 55 of file flock.c.

{
       HANDLE hdl = (HANDLE) _get_osfhandle(fd);
       DWORD low = 1, high = 0;
       OVERLAPPED offset =
       {0, 0, 0, 0, NULL};
       if (hdl < 0)
              return -1;                         /* error in file descriptor */
       /* bug for bug compatible with Unix */
       UnlockFileEx(hdl, 0, low, high, &offset);
       switch (op & ~LOCK_NB) {    /* translate to LockFileEx() op */
              case LOCK_EX:               /* exclusive */
                     if (LockFileEx(hdl, LOCKFILE_EXCLUSIVE_LOCK +
                                          ((op & LOCK_NB) ? LOCKFILE_FAIL_IMMEDIATELY : 0),
                                             0, low, high, &offset))
                            return 0;
                     break;
              case LOCK_SH:               /* shared */
                     if (LockFileEx(hdl, ((op & LOCK_NB) ? LOCKFILE_FAIL_IMMEDIATELY : 0),
                                             0, low, high, &offset))
                            return 0;
                     break;
              case LOCK_UN:               /* unlock */
                     return 0;                   /* always succeeds */
              default:                           /* default */
                     break;
       }
       errno = EINVAL;                           /* bad call */
       return -1;
}

Here is the call graph for this function: