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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [newlib-1.10.0/] [newlib/] [libc/] [stdio/] [flags.c] - Blame information for rev 1773

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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