OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [newlib-1.17.0/] [newlib/] [libc/] [stdio/] [flags.c] - Blame information for rev 158

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.