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 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program; see the file COPYING. If not, write to the Free Software
18 * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21 #include "schilyio.h"
22
23 #ifndef O_BINARY
24 #define O_BINARY 0
25 #endif
26 #ifndef O_LARGEFILE
27 #define O_LARGEFILE 0
28 #endif
29
30 EXPORT int
_cvmod(mode,omode,flag)31 _cvmod(mode, omode, flag)
32 const char *mode;
33 int *omode;
34 int *flag;
35 {
36 while (*mode) {
37 switch (*mode) {
38
39 case 'r': *omode |= O_RDONLY; *flag |= FI_READ; break;
40 case 'w': *omode |= O_WRONLY; *flag |= FI_WRITE; break;
41 case 'e': *omode |= O_EXCL; break;
42 case 'c': *omode |= O_CREAT; *flag |= FI_CREATE; break;
43 case 't': *omode |= O_TRUNC; *flag |= FI_TRUNC; break;
44 case 'a': *omode |= O_APPEND; *flag |= FI_APPEND; break;
45 case 'u': *flag |= FI_UNBUF; break;
46 /* dummy on UNIX */
47 case 'b': *omode |= O_BINARY; *flag |= FI_BINARY; break;
48 /*
49 * XXX do we need this ?
50 * XXX May this be a problem?
51 */
52 case 'l': *omode |= O_LARGEFILE; break;
53 default: raisecond(_badmode, 0L);
54 return (0);
55 }
56 mode++;
57 }
58 if (*flag & FI_READ && *flag & FI_WRITE) {
59 *omode &= ~(O_RDONLY|O_WRONLY);
60 *omode |= O_RDWR;
61 }
62 return (1);
63 }
64