diff options
Diffstat (limited to 'db/os/os_oflags.c')
-rw-r--r-- | db/os/os_oflags.c | 80 |
1 files changed, 63 insertions, 17 deletions
diff --git a/db/os/os_oflags.c b/db/os/os_oflags.c index 6313ba23d..2ffb6db2d 100644 --- a/db/os/os_oflags.c +++ b/db/os/os_oflags.c @@ -1,20 +1,23 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 1997-2003 + * Copyright (c) 1997-2004 * Sleepycat Software. All rights reserved. + * + * $Id: os_oflags.c,v 11.14 2004/07/09 18:39:10 mjc Exp $ */ #include "db_config.h" -#ifndef lint -static const char revid[] = "$Id: os_oflags.c,v 11.11 2003/01/08 05:29:23 bostic Exp $"; -#endif /* not lint */ - #ifndef NO_SYSTEM_INCLUDES #include <sys/types.h> #include <sys/stat.h> +#ifdef HAVE_SHMGET +#include <sys/ipc.h> +#include <sys/shm.h> +#endif + #include <fcntl.h> #endif @@ -60,18 +63,6 @@ __db_oflags(oflags) return (dbflags); } -/* - * __db_omode -- - * Convert a permission string to the correct open(2) flags. - * - * PUBLIC: int __db_omode __P((const char *)); - */ -int -__db_omode(perm) - const char *perm; -{ - int mode; - #ifdef DB_WIN32 #ifndef S_IRUSR #define S_IRUSR S_IREAD /* R for owner */ @@ -111,6 +102,18 @@ __db_omode(perm) #define S_IWOTH 0000002 /* W for other */ #endif #endif /* DB_WIN32 */ + +/* + * __db_omode -- + * Convert a permission string to the correct open(2) flags. + * + * PUBLIC: int __db_omode __P((const char *)); + */ +int +__db_omode(perm) + const char *perm; +{ + int mode; mode = 0; if (perm[0] == 'r') mode |= S_IRUSR; @@ -126,3 +129,46 @@ __db_omode(perm) mode |= S_IWOTH; return (mode); } + +#ifdef HAVE_SHMGET + +#ifndef SHM_R +#define SHM_R 0400 +#endif +#ifndef SHM_W +#define SHM_W 0200 +#endif + +/* + * __db_shm_mode -- + * Map the DbEnv::open method file mode permissions to shmget call + * permissions. + * + * PUBLIC: int __db_shm_mode __P((DB_ENV *)); + */ +int +__db_shm_mode(dbenv) + DB_ENV *dbenv; +{ + int mode; + + /* Default to r/w owner, r/w group. */ + if (dbenv->db_mode == 0) + return (SHM_R | SHM_W | SHM_R >> 3 | SHM_W >> 3); + + mode = 0; + if (dbenv->db_mode & S_IRUSR) + mode |= SHM_R; + if (dbenv->db_mode & S_IWUSR) + mode |= SHM_W; + if (dbenv->db_mode & S_IRGRP) + mode |= SHM_R >> 3; + if (dbenv->db_mode & S_IWGRP) + mode |= SHM_W >> 3; + if (dbenv->db_mode & S_IROTH) + mode |= SHM_R >> 6; + if (dbenv->db_mode & S_IWOTH) + mode |= SHM_W >> 6; + return (mode); +} +#endif |