Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 07b14dd

Browse files
committed
add locking where it exists
1 parent ef38b78 commit 07b14dd

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

Modules/dbhashmodule.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -334,19 +334,30 @@ dbhashopen(self, args)
334334
return NULL;
335335
if (flag != NULL) {
336336
/* XXX need a way to pass O_EXCL, O_EXLOCK, O_NONBLOCK, O_SHLOCK */
337-
if (strcmp(flag, "r") == 0)
337+
if (flag[0] == 'r')
338338
flags = O_RDONLY;
339-
else if (strcmp(flag, "w") == 0)
339+
else if (flag[0] == 'w')
340340
flags = O_RDWR;
341-
else if (strcmp(flag, "c") == 0)
341+
else if (flag[0] == 'c')
342342
flags = O_RDWR|O_CREAT;
343-
else if (strcmp(flag, "n") == 0)
343+
else if (flag[0] == 'n')
344344
flags = O_RDWR|O_CREAT|O_TRUNC;
345345
else {
346346
err_setstr(DbhashError,
347-
"Flag should be one of 'r', 'w', 'c' or 'n'");
347+
"Flag should begin with 'r', 'w', 'c' or 'n'");
348348
return NULL;
349349
}
350+
if (flag[1] == 'l') {
351+
#if defined(O_EXLOCK) && defined(O_SHLOCK)
352+
if (flag[0] == 'r')
353+
flags |= O_SHLOCK;
354+
else
355+
flags |= O_EXLOCK;
356+
#else
357+
err_setstr(DbhashError, "locking not supported on this platform");
358+
return NULL;
359+
#endif
360+
}
350361
}
351362
return newdbhashobject(file, flags, mode,
352363
bsize, ffactor, nelem, cachesize, hash, lorder);

0 commit comments

Comments
 (0)