1N/A/*-
1N/A * See the file LICENSE for redistribution information.
1N/A *
1N/A * Copyright (c) 1997, 1998
1N/A * Sleepycat Software. All rights reserved.
1N/A */
1N/A
1N/A#include "config.h"
1N/A
1N/A#ifndef lint
1N/Astatic const char sccsid[] = "@(#)os_oflags.c 10.6 (Sleepycat) 4/19/98";
1N/A#endif /* not lint */
1N/A
1N/A#ifndef NO_SYSTEM_INCLUDES
1N/A#include <sys/types.h>
1N/A#include <sys/stat.h>
1N/A
1N/A#include <fcntl.h>
1N/A#endif
1N/A
1N/A#include "db_int.h"
1N/A
1N/A/*
1N/A * __db_oflags --
1N/A * Convert open(2) flags to DB flags.
1N/A *
1N/A * PUBLIC: u_int32_t __db_oflags __P((int));
1N/A */
1N/Au_int32_t
1N/A__db_oflags(oflags)
1N/A int oflags;
1N/A{
1N/A u_int32_t dbflags;
1N/A
1N/A /*
1N/A * XXX
1N/A * Convert POSIX 1003.1 open(2) flags to DB flags. Not an exact
1N/A * science as most POSIX implementations don't have a flag value
1N/A * for O_RDONLY, it's simply the lack of a write flag.
1N/A */
1N/A dbflags = 0;
1N/A if (oflags & O_CREAT)
1N/A dbflags |= DB_CREATE;
1N/A if (!(oflags & (O_RDWR | O_WRONLY)) || oflags & O_RDONLY)
1N/A dbflags |= DB_RDONLY;
1N/A if (oflags & O_TRUNC)
1N/A dbflags |= DB_TRUNCATE;
1N/A return (dbflags);
1N/A}
1N/A
1N/A/*
1N/A * __db_omode --
1N/A * Convert a permission string to the correct open(2) flags.
1N/A *
1N/A * PUBLIC: int __db_omode __P((const char *));
1N/A */
1N/Aint
1N/A__db_omode(perm)
1N/A const char *perm;
1N/A{
1N/A int mode;
1N/A
1N/A#ifndef S_IRUSR
1N/A#if defined(_WIN32) || defined(WIN16)
1N/A#define S_IRUSR S_IREAD /* R for owner */
1N/A#define S_IWUSR S_IWRITE /* W for owner */
1N/A#define S_IRGRP 0 /* R for group */
1N/A#define S_IWGRP 0 /* W for group */
1N/A#define S_IROTH 0 /* R for other */
1N/A#define S_IWOTH 0 /* W for other */
1N/A#else
1N/A#define S_IRUSR 0000400 /* R for owner */
1N/A#define S_IWUSR 0000200 /* W for owner */
1N/A#define S_IRGRP 0000040 /* R for group */
1N/A#define S_IWGRP 0000020 /* W for group */
1N/A#define S_IROTH 0000004 /* R for other */
1N/A#define S_IWOTH 0000002 /* W for other */
1N/A#endif /* _WIN32 || WIN16 */
1N/A#endif
1N/A mode = 0;
1N/A if (perm[0] == 'r')
1N/A mode |= S_IRUSR;
1N/A if (perm[1] == 'w')
1N/A mode |= S_IWUSR;
1N/A if (perm[2] == 'r')
1N/A mode |= S_IRGRP;
1N/A if (perm[3] == 'w')
1N/A mode |= S_IWGRP;
1N/A if (perm[4] == 'r')
1N/A mode |= S_IROTH;
1N/A if (perm[5] == 'w')
1N/A mode |= S_IWOTH;
1N/A return (mode);
1N/A}