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