Commit b60781ce authored by Guido van Rossum's avatar Guido van Rossum

add locking where it exists

parent c874c2a9
...@@ -334,19 +334,30 @@ dbhashopen(self, args) ...@@ -334,19 +334,30 @@ dbhashopen(self, args)
return NULL; return NULL;
if (flag != NULL) { if (flag != NULL) {
/* XXX need a way to pass O_EXCL, O_EXLOCK, O_NONBLOCK, O_SHLOCK */ /* 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; flags = O_RDONLY;
else if (strcmp(flag, "w") == 0) else if (flag[0] == 'w')
flags = O_RDWR; flags = O_RDWR;
else if (strcmp(flag, "c") == 0) else if (flag[0] == 'c')
flags = O_RDWR|O_CREAT; flags = O_RDWR|O_CREAT;
else if (strcmp(flag, "n") == 0) else if (flag[0] == 'n')
flags = O_RDWR|O_CREAT|O_TRUNC; flags = O_RDWR|O_CREAT|O_TRUNC;
else { else {
err_setstr(DbhashError, err_setstr(DbhashError,
"Flag should be one of 'r', 'w', 'c' or 'n'"); "Flag should begin with 'r', 'w', 'c' or 'n'");
return NULL; 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, return newdbhashobject(file, flags, mode,
bsize, ffactor, nelem, cachesize, hash, lorder); bsize, ffactor, nelem, cachesize, hash, lorder);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment