sl@0
|
1 |
/* FLAGS.C
|
sl@0
|
2 |
*
|
sl@0
|
3 |
* Portions Copyright (c) 1990-1999 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
4 |
* All rights reserved.
|
sl@0
|
5 |
*/
|
sl@0
|
6 |
|
sl@0
|
7 |
/* No user fns here. Pesch 15apr92 */
|
sl@0
|
8 |
|
sl@0
|
9 |
/*
|
sl@0
|
10 |
* Copyright (c) 1990 Regents of the University of California.
|
sl@0
|
11 |
* All rights reserved.
|
sl@0
|
12 |
*
|
sl@0
|
13 |
* Redistribution and use in source and binary forms are permitted
|
sl@0
|
14 |
* provided that the above copyright notice and this paragraph are
|
sl@0
|
15 |
* duplicated in all such forms and that any documentation,
|
sl@0
|
16 |
* advertising materials, and other materials related to such
|
sl@0
|
17 |
* distribution and use acknowledge that the software was developed
|
sl@0
|
18 |
* by the University of California, Berkeley. The name of the
|
sl@0
|
19 |
* University may not be used to endorse or promote products derived
|
sl@0
|
20 |
* from this software without specific prior written permission.
|
sl@0
|
21 |
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
sl@0
|
22 |
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
sl@0
|
23 |
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
sl@0
|
24 |
*/
|
sl@0
|
25 |
|
sl@0
|
26 |
#include <stdio_r.h>
|
sl@0
|
27 |
#include <time.h>
|
sl@0
|
28 |
#include <fcntl.h>
|
sl@0
|
29 |
#include "LOCAL.H"
|
sl@0
|
30 |
|
sl@0
|
31 |
#include <errno.h>
|
sl@0
|
32 |
#include <sys/types.h>
|
sl@0
|
33 |
|
sl@0
|
34 |
/*
|
sl@0
|
35 |
* Return the (stdio) flags for a given mode. Store the flags
|
sl@0
|
36 |
* to be passed to an open() syscall through *optr.
|
sl@0
|
37 |
* Return 0 on error.
|
sl@0
|
38 |
*/
|
sl@0
|
39 |
|
sl@0
|
40 |
|
sl@0
|
41 |
int __sflags (struct _reent *ptr, const wchar_t *mode, int *optr)
|
sl@0
|
42 |
{
|
sl@0
|
43 |
register int ret, m, o;
|
sl@0
|
44 |
|
sl@0
|
45 |
switch (mode[0])
|
sl@0
|
46 |
{
|
sl@0
|
47 |
case L'r': /* open for reading */
|
sl@0
|
48 |
ret = __SRD;
|
sl@0
|
49 |
m = O_RDONLY;
|
sl@0
|
50 |
o = 0;
|
sl@0
|
51 |
break;
|
sl@0
|
52 |
|
sl@0
|
53 |
case L'w': /* open for writing */
|
sl@0
|
54 |
ret = __SWR;
|
sl@0
|
55 |
m = O_WRONLY;
|
sl@0
|
56 |
o = O_CREAT | O_TRUNC;
|
sl@0
|
57 |
break;
|
sl@0
|
58 |
|
sl@0
|
59 |
case L'a': /* open for appending */
|
sl@0
|
60 |
ret = __SWR | __SAPP;
|
sl@0
|
61 |
m = O_WRONLY;
|
sl@0
|
62 |
o = O_CREAT | O_APPEND;
|
sl@0
|
63 |
break;
|
sl@0
|
64 |
|
sl@0
|
65 |
default: /* illegal mode */
|
sl@0
|
66 |
ptr->_errno = EINVAL;
|
sl@0
|
67 |
return (0);
|
sl@0
|
68 |
}
|
sl@0
|
69 |
if (mode[1] == L'+' || mode[2] == L'+')
|
sl@0
|
70 |
{
|
sl@0
|
71 |
ret = __SRW;
|
sl@0
|
72 |
m = O_RDWR;
|
sl@0
|
73 |
}
|
sl@0
|
74 |
if (mode[1] == L'b' || mode[2] == L'b')
|
sl@0
|
75 |
{
|
sl@0
|
76 |
m |= O_BINARY;
|
sl@0
|
77 |
}
|
sl@0
|
78 |
else
|
sl@0
|
79 |
{
|
sl@0
|
80 |
m |= O_TEXT;
|
sl@0
|
81 |
}
|
sl@0
|
82 |
*optr = m | o;
|
sl@0
|
83 |
return ret;
|
sl@0
|
84 |
}
|