home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / D / LIBC / LIBC-4.6 / LIBC-4 / libc-linux / sysdeps / linux / __flock.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-26  |  1.7 KB  |  69 lines

  1. /* Copyright (C) 1993 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3.  
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public License as
  6. published by the Free Software Foundation; either version 2 of the
  7. License, or (at your option) any later version.
  8.  
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12. Library General Public License for more details.
  13.  
  14. You should have received a copy of the GNU Library General Public
  15. License along with the GNU C Library; see the file COPYING.LIB.  If
  16. not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  17. Cambridge, MA 02139, USA.  */
  18.  
  19. #include <ansidecl.h>
  20. #include <errno.h>
  21. #include <unistd.h>
  22. #include <fcntl.h>
  23. #include <sys/file.h>
  24.  
  25. /* Apply or remove an advisory lock, according to OPERATION,
  26.    on the file FD refers to.  */
  27. int
  28. DEFUN(__flock, (fd, operation), int fd AND int operation)
  29. {
  30.   struct flock flock;
  31.   int cmd;
  32.  
  33.   switch (operation & ~LOCK_NB) {
  34.   case LOCK_SH:
  35. #ifdef __linux__
  36.     flock.l_type = F_SHLCK;
  37. #else
  38.     flock.l_type = F_RDLCK;
  39. #endif
  40.     break;
  41.   case LOCK_EX:
  42. #ifdef __linux__
  43.     flock.l_type = F_EXLCK;
  44. #else
  45.     flock.l_type = F_WRLCK;
  46. #endif
  47.     break;
  48.   case LOCK_UN:
  49.     flock.l_type = F_UNLCK;
  50.     break;
  51.   default:
  52.     errno = EINVAL;
  53.     return -1;
  54.   }
  55.  
  56.   flock.l_whence = SEEK_SET;
  57.   flock.l_start = flock.l_len = 0L;
  58.  
  59.   cmd = (operation & LOCK_NB) ?  F_SETLK : F_SETLKW;
  60.  
  61.   return (__fcntl (fd, cmd, &flock));
  62. }
  63.  
  64.  
  65. #include <gnu-stabs.h>
  66. #ifdef weak_alias
  67. weak_alias (__flock, flock);
  68. #endif
  69.