FreeBASIC  0.91.0
file_lock.c
Go to the documentation of this file.
1 /* lock and unlock functions */
2 
3 #include "fb.h"
4 
5 /*:::::*/
6 int fb_FileLockEx( FB_FILE *handle, fb_off_t inipos, fb_off_t endpos )
7 {
8  int res;
9 
10  if( inipos < 1 || endpos <= inipos )
12 
13  if( !FB_HANDLE_USED(handle) )
15 
16  FB_LOCK();
17 
18  /* convert to 0 based file i/o */
19  --inipos;
20  if( handle->mode == FB_FILE_MODE_RANDOM ) {
21  inipos = handle->len * inipos;
22  endpos = inipos + handle->len;
23  } else {
24  --endpos;
25  }
26 
27  if( handle->hooks->pfnLock != NULL) {
28  res = handle->hooks->pfnLock( handle, inipos-1, endpos - inipos );
29  } else {
31  }
32 
33  FB_UNLOCK();
34 
35  return res;
36 }
37 
38 /*:::::*/
39 FBCALL int fb_FileLock( int fnum, unsigned int inipos, unsigned int endpos )
40 {
41  return fb_FileLockEx(FB_FILE_TO_HANDLE(fnum), inipos, endpos);
42 }
43 
44 /*:::::*/
45 FBCALL int fb_FileLockLarge( int fnum, long long inipos, long long endpos )
46 {
47  return fb_FileLockEx(FB_FILE_TO_HANDLE(fnum), inipos, endpos);
48 }
49 
50 /*:::::*/
52 {
53  int res;
54 
55  if( inipos < 1 || endpos <= inipos )
57 
58  FB_LOCK();
59 
60  /* convert to 0 based file i/o */
61  --inipos;
62  if( handle->mode == FB_FILE_MODE_RANDOM ) {
63  inipos = handle->len * inipos;
64  endpos = inipos + handle->len;
65  } else {
66  --endpos;
67  }
68 
69  if( handle->hooks != NULL ) {
70  if (handle->hooks->pfnUnlock!=NULL) {
71  res = handle->hooks->pfnUnlock( handle, inipos, endpos - inipos );
72  } else {
74  }
75 
76  } else {
78  }
79 
80  FB_UNLOCK();
81 
82  return res;
83 }
84 
85 /*:::::*/
86 FBCALL int fb_FileUnlock( int fnum, unsigned int inipos, unsigned int endpos )
87 {
88  if( !FB_FILE_INDEX_VALID(fnum) )
90  return fb_FileUnlockEx(FB_FILE_TO_HANDLE(fnum), inipos, endpos);
91 }
92 
93 /*:::::*/
94 FBCALL int fb_FileUnlockLarge( int fnum, long long inipos, long long endpos )
95 {
96  if( !FB_FILE_INDEX_VALID(fnum) )
98  return fb_FileUnlockEx(FB_FILE_TO_HANDLE(fnum), inipos, endpos);
99 }