os_oflags.c

Go to the documentation of this file.
00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 1997, 1998, 1999, 2000
00005  *      Sleepycat Software.  All rights reserved.
00006  */
00007 
00008 #include "config.h"
00009 
00010 #ifndef lint
00011 static const char revid[] = "$Id: os__oflags_8c-source.html,v 1.1 2008/06/08 10:21:24 sebdiaz Exp $";
00012 #endif /* not lint */
00013 
00014 #ifndef NO_SYSTEM_INCLUDES
00015 #include <sys/types.h>
00016 #include <sys/stat.h>
00017 
00018 #include <fcntl.h>
00019 #endif
00020 
00021 #include "db_int.h"
00022 
00023 /*
00024  * CDB___db_oflags --
00025  *      Convert open(2) flags to DB flags.
00026  *
00027  * PUBLIC: u_int32_t CDB___db_oflags __P((int));
00028  */
00029 u_int32_t
00030 CDB___db_oflags(oflags)
00031         int oflags;
00032 {
00033         u_int32_t dbflags;
00034 
00035         dbflags = 0;
00036 
00037         if (oflags & O_CREAT)
00038                 dbflags |= DB_CREATE;
00039 
00040         if (oflags & O_TRUNC)
00041                 dbflags |= DB_TRUNCATE;
00042 
00043         /*
00044          * !!!
00045          * Convert POSIX 1003.1 open(2) mode flags to DB flags.  This isn't
00046          * an exact science as few POSIX implementations have a flag value
00047          * for O_RDONLY, it's simply the lack of a write flag.
00048          */
00049 #ifndef O_ACCMODE
00050 #define O_ACCMODE       (O_RDONLY | O_RDWR | O_WRONLY)
00051 #endif
00052         switch (oflags & O_ACCMODE) {
00053         case O_RDWR:
00054         case O_WRONLY:
00055                 break;
00056         default:
00057                 dbflags |= DB_RDONLY;
00058                 break;
00059         }
00060         return (dbflags);
00061 }
00062 
00063 /*
00064  * CDB___db_omode --
00065  *      Convert a permission string to the correct open(2) flags.
00066  *
00067  * PUBLIC: int CDB___db_omode __P((const char *));
00068  */
00069 int
00070 CDB___db_omode(perm)
00071         const char *perm;
00072 {
00073         int mode;
00074 
00075 #ifndef S_IRUSR
00076 #if defined(_WIN32) || defined(WIN16)
00077 #define S_IRUSR S_IREAD         /* R for owner */
00078 #define S_IWUSR S_IWRITE        /* W for owner */
00079 #define S_IRGRP 0               /* R for group */
00080 #define S_IWGRP 0               /* W for group */
00081 #define S_IROTH 0               /* R for other */
00082 #define S_IWOTH 0               /* W for other */
00083 #else
00084 #define S_IRUSR 0000400         /* R for owner */
00085 #define S_IWUSR 0000200         /* W for owner */
00086 #define S_IRGRP 0000040         /* R for group */
00087 #define S_IWGRP 0000020         /* W for group */
00088 #define S_IROTH 0000004         /* R for other */
00089 #define S_IWOTH 0000002         /* W for other */
00090 #endif /* _WIN32 || WIN16 */
00091 #endif
00092         mode = 0;
00093         if (perm[0] == 'r')
00094                 mode |= S_IRUSR;
00095         if (perm[1] == 'w')
00096                 mode |= S_IWUSR;
00097         if (perm[2] == 'r')
00098                 mode |= S_IRGRP;
00099         if (perm[3] == 'w')
00100                 mode |= S_IWGRP;
00101         if (perm[4] == 'r')
00102                 mode |= S_IROTH;
00103         if (perm[5] == 'w')
00104                 mode |= S_IWOTH;
00105         return (mode);
00106 }

Generated on Sun Jun 8 10:56:38 2008 for GNUmifluz by  doxygen 1.5.5