Changeset 690
- Timestamp:
- Sep 11, 2003, 3:17:06 AM (22 years ago)
- Location:
- trunk/src/emx/src/lib
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/emx/src/lib/io/fcntl.c
-
Property cvs2svn:cvs-rev
changed from
1.4
to1.5
r689 r690 112 112 case F_GETOSFD: 113 113 return __fcntl (handle, request, 0); 114 115 case F_GETLK: /* get record locking information */ 116 case F_SETLK: /* set record locking information */ 117 case F_SETLKW: /* F_SETLK; wait if blocked */ 118 va_start (va, request); 119 arg = va_arg (va, /*struct flock **/ int); 120 va_end (va); 121 return __fcntl (handle, request, arg); 114 122 } 115 123 -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/lib/sys/__fcntl.c
-
Property cvs2svn:cvs-rev
changed from
1.2
to1.3
r689 r690 4 4 #include <fcntl.h> 5 5 #include <errno.h> 6 #include <limits.h> 7 #include <io.h> 6 8 #include <os2emx.h> 7 9 #include <emx/syscalls.h> 8 10 #include "syscalls.h" 11 12 static int __fcntl_locking(int handle, int request, struct flock *pflock); 9 13 10 14 int __fcntl (int handle, int request, int arg) … … 47 51 } 48 52 return 0; 53 54 case F_GETLK: /* get record locking information */ 55 case F_SETLK: /* set record locking information */ 56 case F_SETLKW: /* F_SETLK; wait if blocked */ 57 return __fcntl_locking(handle, request, (struct flock*)arg); 58 49 59 default: 50 60 errno = EINVAL; … … 52 62 } 53 63 } 64 65 66 /* Handle locking requests. 67 68 Please excuse the Hungarian and indenting used in this code, 69 it's take from elsewhere. */ 70 71 static int __fcntl_locking (int handle, int request, struct flock *pflock) 72 { 73 APIRET rc; 74 FILESTATUS3 fsts3; 75 76 /* check input */ 77 /** @todo: Implement F_GETLK */ 78 if (!pflock || request == F_GETLK) 79 { 80 errno = EINVAL; 81 return -1; 82 } 83 84 /* check handle & get filesize. */ 85 rc = DosQueryFileInfo (handle, FIL_STANDARD, &fsts3, sizeof(fsts3)); 86 if (!rc) 87 { 88 FILELOCK FileLockDummy = {0, 0}; 89 FILELOCK FileLock; 90 PFILELOCK pFLLock; 91 PFILELOCK pFLUnlock; 92 ULONG fAccess; 93 ULONG ulTimeout; 94 95 /* offset */ 96 switch (pflock->l_whence) 97 { 98 case SEEK_SET: FileLock.lOffset = pflock->l_start; break; 99 case SEEK_CUR: FileLock.lOffset = tell (handle) + pflock->l_start; break; 100 case SEEK_END: FileLock.lOffset = fsts3.cbFile - pflock->l_start; break; 101 default: 102 errno = EINVAL; 103 return -1; 104 } 105 if (FileLock.lOffset < 0) 106 { 107 errno = EINVAL; 108 return -1; 109 } 110 111 /* range */ 112 FileLock.lRange = pflock->l_len ? pflock->l_len : LONG_MAX; 113 114 /* flags and order */ 115 fAccess = 0; /* exclusive */ 116 switch (pflock->l_type) 117 { 118 case F_UNLCK: 119 pFLLock = &FileLockDummy; 120 pFLUnlock = &FileLock; 121 break; 122 123 case F_RDLCK: 124 fAccess = 1; /* shared */ 125 case F_WRLCK: 126 pFLLock = &FileLock; 127 pFLUnlock = &FileLockDummy; 128 break; 129 130 default: 131 errno = EINVAL; 132 return -1; 133 } 134 135 /* timeout */ 136 if (request == F_SETLKW) 137 ulTimeout = SEM_INDEFINITE_WAIT; 138 else 139 ulTimeout = SEM_IMMEDIATE_RETURN; 140 141 /* Do work. */ 142 rc = DosSetFileLocks (handle, pFLUnlock, pFLLock, ulTimeout, fAccess); 143 } 144 145 /* done */ 146 if (!rc) 147 return 0; 148 _sys_set_errno (rc); 149 return -1; 150 } 151 -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.