1 /* @(#)cvmod.c	2.9 04/08/08 Copyright 1986, 1995-2003 J. Schilling */
2 /*
3  *	Copyright (c) 1986, 1995-2003 J. Schilling
4  */
5 /*
6  * The contents of this file are subject to the terms of the
7  * Common Development and Distribution License, Version 1.0 only
8  * (the "License").  You may not use this file except in compliance
9  * with the License.
10  *
11  * See the file CDDL.Schily.txt in this distribution for details.
12  * A copy of the CDDL is also available via the Internet at
13  * http://www.opensource.org/licenses/cddl1.txt
14  *
15  * When distributing Covered Code, include this CDDL HEADER in each
16  * file and include the License file CDDL.Schily.txt from this distribution.
17  */
18 
19 #include "schilyio.h"
20 
21 #ifndef	O_BINARY
22 #define	O_BINARY	0
23 #endif
24 #ifndef	O_LARGEFILE
25 #define	O_LARGEFILE	0
26 #endif
27 
28 EXPORT int
29 _cvmod(mode, omode, flag)
30 	const char	*mode;
31 	int		*omode;
32 	int		*flag;
33 {
34 	while (*mode) {
35 		switch (*mode) {
36 
37 		case 'r':   *omode |= O_RDONLY;	*flag |= FI_READ;	break;
38 		case 'w':   *omode |= O_WRONLY;	*flag |= FI_WRITE;	break;
39 		case 'e':   *omode |= O_EXCL;				break;
40 		case 'c':   *omode |= O_CREAT;	*flag |= FI_CREATE;	break;
41 		case 't':   *omode |= O_TRUNC;	*flag |= FI_TRUNC;	break;
42 		case 'a':   *omode |= O_APPEND;	*flag |= FI_APPEND;	break;
43 		case 'u':			*flag |= FI_UNBUF;	break;
44 			/* dummy on UNIX */
45 		case 'b':   *omode |= O_BINARY; *flag |= FI_BINARY;	break;
46 			/*
47 			 * XXX do we need this ?
48 			 * XXX May this be a problem?
49 			 */
50 		case 'l':   *omode |= O_LARGEFILE;			break;
51 		default:    raisecond(_badmode, 0L);
52 			    return (0);
53 		}
54 		mode++;
55 	}
56 	if (*flag & FI_READ && *flag & FI_WRITE) {
57 		*omode &= ~(O_RDONLY|O_WRONLY);
58 		*omode |= O_RDWR;
59 	}
60 	return (1);
61 }
62