xref: /illumos-gate/usr/src/cmd/sendmail/db/os/os_oflags.c (revision eb0cc229f19c437a6b538d3ac0d0443268290b7e)
1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 1997, 1998
5  *	Sleepycat Software.  All rights reserved.
6  */
7 
8 #include "config.h"
9 
10 #ifndef lint
11 static const char sccsid[] = "@(#)os_oflags.c	10.6 (Sleepycat) 4/19/98";
12 #endif /* not lint */
13 
14 #ifndef NO_SYSTEM_INCLUDES
15 #include <sys/types.h>
16 #include <sys/stat.h>
17 
18 #include <fcntl.h>
19 #endif
20 
21 #include "db_int.h"
22 
23 /*
24  * __db_oflags --
25  *	Convert open(2) flags to DB flags.
26  *
27  * PUBLIC: u_int32_t __db_oflags __P((int));
28  */
29 u_int32_t
30 __db_oflags(oflags)
31 	int oflags;
32 {
33 	u_int32_t dbflags;
34 
35 	/*
36 	 * XXX
37 	 * Convert POSIX 1003.1 open(2) flags to DB flags.  Not an exact
38 	 * science as most POSIX implementations don't have a flag value
39 	 * for O_RDONLY, it's simply the lack of a write flag.
40 	 */
41 	dbflags = 0;
42 	if (oflags & O_CREAT)
43 		dbflags |= DB_CREATE;
44 	if (!(oflags & (O_RDWR | O_WRONLY)) || oflags & O_RDONLY)
45 		dbflags |= DB_RDONLY;
46 	if (oflags & O_TRUNC)
47 		dbflags |= DB_TRUNCATE;
48 	return (dbflags);
49 }
50 
51 /*
52  * __db_omode --
53  *	Convert a permission string to the correct open(2) flags.
54  *
55  * PUBLIC: int __db_omode __P((const char *));
56  */
57 int
58 __db_omode(perm)
59 	const char *perm;
60 {
61 	int mode;
62 
63 #ifndef	S_IRUSR
64 #if defined(_WIN32) || defined(WIN16)
65 #define	S_IRUSR	S_IREAD		/* R for owner */
66 #define	S_IWUSR	S_IWRITE	/* W for owner */
67 #define	S_IRGRP	0		/* R for group */
68 #define	S_IWGRP	0		/* W for group */
69 #define	S_IROTH	0		/* R for other */
70 #define	S_IWOTH	0		/* W for other */
71 #else
72 #define	S_IRUSR	0000400		/* R for owner */
73 #define	S_IWUSR	0000200		/* W for owner */
74 #define	S_IRGRP	0000040		/* R for group */
75 #define	S_IWGRP	0000020		/* W for group */
76 #define	S_IROTH	0000004		/* R for other */
77 #define	S_IWOTH	0000002		/* W for other */
78 #endif /* _WIN32 || WIN16 */
79 #endif
80 	mode = 0;
81 	if (perm[0] == 'r')
82 		mode |= S_IRUSR;
83 	if (perm[1] == 'w')
84 		mode |= S_IWUSR;
85 	if (perm[2] == 'r')
86 		mode |= S_IRGRP;
87 	if (perm[3] == 'w')
88 		mode |= S_IWGRP;
89 	if (perm[4] == 'r')
90 		mode |= S_IROTH;
91 	if (perm[5] == 'w')
92 		mode |= S_IWOTH;
93 	return (mode);
94 }
95