mirror of
https://github.com/python/cpython
synced 2024-09-19 14:51:29 +00:00
add locking where it exists
This commit is contained in:
parent
ef38b78f94
commit
07b14dd8bc
|
@ -334,19 +334,30 @@ dbhashopen(self, args)
|
|||
return NULL;
|
||||
if (flag != NULL) {
|
||||
/* XXX need a way to pass O_EXCL, O_EXLOCK, O_NONBLOCK, O_SHLOCK */
|
||||
if (strcmp(flag, "r") == 0)
|
||||
if (flag[0] == 'r')
|
||||
flags = O_RDONLY;
|
||||
else if (strcmp(flag, "w") == 0)
|
||||
else if (flag[0] == 'w')
|
||||
flags = O_RDWR;
|
||||
else if (strcmp(flag, "c") == 0)
|
||||
else if (flag[0] == 'c')
|
||||
flags = O_RDWR|O_CREAT;
|
||||
else if (strcmp(flag, "n") == 0)
|
||||
else if (flag[0] == 'n')
|
||||
flags = O_RDWR|O_CREAT|O_TRUNC;
|
||||
else {
|
||||
err_setstr(DbhashError,
|
||||
"Flag should be one of 'r', 'w', 'c' or 'n'");
|
||||
"Flag should begin with 'r', 'w', 'c' or 'n'");
|
||||
return NULL;
|
||||
}
|
||||
if (flag[1] == 'l') {
|
||||
#if defined(O_EXLOCK) && defined(O_SHLOCK)
|
||||
if (flag[0] == 'r')
|
||||
flags |= O_SHLOCK;
|
||||
else
|
||||
flags |= O_EXLOCK;
|
||||
#else
|
||||
err_setstr(DbhashError, "locking not supported on this platform");
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
return newdbhashobject(file, flags, mode,
|
||||
bsize, ffactor, nelem, cachesize, hash, lorder);
|
||||
|
|
Loading…
Reference in a new issue