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