1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/cstdlib/LSTDIO/FLAGS.C Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,84 @@
1.4 +/* FLAGS.C
1.5 + *
1.6 + * Portions Copyright (c) 1990-1999 Nokia Corporation and/or its subsidiary(-ies).
1.7 + * All rights reserved.
1.8 + */
1.9 +
1.10 +/* No user fns here. Pesch 15apr92 */
1.11 +
1.12 +/*
1.13 + * Copyright (c) 1990 Regents of the University of California.
1.14 + * All rights reserved.
1.15 + *
1.16 + * Redistribution and use in source and binary forms are permitted
1.17 + * provided that the above copyright notice and this paragraph are
1.18 + * duplicated in all such forms and that any documentation,
1.19 + * advertising materials, and other materials related to such
1.20 + * distribution and use acknowledge that the software was developed
1.21 + * by the University of California, Berkeley. The name of the
1.22 + * University may not be used to endorse or promote products derived
1.23 + * from this software without specific prior written permission.
1.24 + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
1.25 + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
1.26 + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1.27 + */
1.28 +
1.29 +#include <stdio_r.h>
1.30 +#include <time.h>
1.31 +#include <fcntl.h>
1.32 +#include "LOCAL.H"
1.33 +
1.34 +#include <errno.h>
1.35 +#include <sys/types.h>
1.36 +
1.37 +/*
1.38 + * Return the (stdio) flags for a given mode. Store the flags
1.39 + * to be passed to an open() syscall through *optr.
1.40 + * Return 0 on error.
1.41 + */
1.42 +
1.43 +
1.44 +int __sflags (struct _reent *ptr, const wchar_t *mode, int *optr)
1.45 +{
1.46 + register int ret, m, o;
1.47 +
1.48 + switch (mode[0])
1.49 + {
1.50 + case L'r': /* open for reading */
1.51 + ret = __SRD;
1.52 + m = O_RDONLY;
1.53 + o = 0;
1.54 + break;
1.55 +
1.56 + case L'w': /* open for writing */
1.57 + ret = __SWR;
1.58 + m = O_WRONLY;
1.59 + o = O_CREAT | O_TRUNC;
1.60 + break;
1.61 +
1.62 + case L'a': /* open for appending */
1.63 + ret = __SWR | __SAPP;
1.64 + m = O_WRONLY;
1.65 + o = O_CREAT | O_APPEND;
1.66 + break;
1.67 +
1.68 + default: /* illegal mode */
1.69 + ptr->_errno = EINVAL;
1.70 + return (0);
1.71 + }
1.72 + if (mode[1] == L'+' || mode[2] == L'+')
1.73 + {
1.74 + ret = __SRW;
1.75 + m = O_RDWR;
1.76 + }
1.77 + if (mode[1] == L'b' || mode[2] == L'b')
1.78 + {
1.79 + m |= O_BINARY;
1.80 + }
1.81 + else
1.82 + {
1.83 + m |= O_TEXT;
1.84 + }
1.85 + *optr = m | o;
1.86 + return ret;
1.87 +}