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/] [stdio.c] - Blame information for rev 387

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

Line No. Rev Author Line
1 148 jeremybenn
/*
2
 * Copyright (c) 1990 The 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 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16
 */
17
/* No user fns here.  Pesch 15apr92. */
18
 
19
#include <_ansi.h>
20
#include <reent.h>
21
#include <stdio.h>
22
#include <sys/types.h>
23
#include <fcntl.h>
24
#include <sys/unistd.h>
25
#include "local.h"
26
 
27
/*
28
 * Small standard I/O/seek/close functions.
29
 * These maintain the `known seek offset' for seek optimisation.
30
 */
31
 
32
_READ_WRITE_RETURN_TYPE
33
_DEFUN(__sread, (ptr, cookie, buf, n),
34
       struct _reent *ptr _AND
35
       void *cookie _AND
36
       char *buf _AND
37
       int n)
38
{
39
  register FILE *fp = (FILE *) cookie;
40
  register int ret;
41
 
42
#ifdef __SCLE
43
  int oldmode = 0;
44
  if (fp->_flags & __SCLE)
45
    oldmode = setmode (fp->_file, O_BINARY);
46
#endif
47
 
48
  ret = _read_r (ptr, fp->_file, buf, n);
49
 
50
#ifdef __SCLE
51
  if (oldmode)
52
    setmode (fp->_file, oldmode);
53
#endif
54
 
55
  /* If the read succeeded, update the current offset.  */
56
 
57
  if (ret >= 0)
58
    fp->_offset += ret;
59
  else
60
    fp->_flags &= ~__SOFF;      /* paranoia */
61
  return ret;
62
}
63
 
64
_READ_WRITE_RETURN_TYPE
65
_DEFUN(__swrite, (ptr, cookie, buf, n),
66
       struct _reent *ptr _AND
67
       void *cookie _AND
68
       char const *buf _AND
69
       int n)
70
{
71
  register FILE *fp = (FILE *) cookie;
72
  int w;
73
#ifdef __SCLE
74
  int oldmode=0;
75
#endif
76
 
77
  if (fp->_flags & __SAPP)
78
    _lseek_r (ptr, fp->_file, (_off_t) 0, SEEK_END);
79
  fp->_flags &= ~__SOFF;        /* in case O_APPEND mode is set */
80
 
81
#ifdef __SCLE
82
  if (fp->_flags & __SCLE)
83
    oldmode = setmode (fp->_file, O_BINARY);
84
#endif
85
 
86
  w = _write_r (ptr, fp->_file, buf, n);
87
 
88
#ifdef __SCLE
89
  if (oldmode)
90
    setmode (fp->_file, oldmode);
91
#endif
92
 
93
  return w;
94
}
95
 
96
_fpos_t
97
_DEFUN(__sseek, (ptr, cookie, offset, whence),
98
       struct _reent *ptr _AND
99
       void *cookie _AND
100
       _fpos_t offset _AND
101
       int whence)
102
{
103
  register FILE *fp = (FILE *) cookie;
104
  register _off_t ret;
105
 
106
  ret = _lseek_r (ptr, fp->_file, (_off_t) offset, whence);
107
  if (ret == -1L)
108
    fp->_flags &= ~__SOFF;
109
  else
110
    {
111
      fp->_flags |= __SOFF;
112
      fp->_offset = ret;
113
    }
114
  return ret;
115
}
116
 
117
int
118
_DEFUN(__sclose, (ptr, cookie),
119
       struct _reent *ptr _AND
120
       void *cookie)
121
{
122
  FILE *fp = (FILE *) cookie;
123
 
124
  return _close_r (ptr, fp->_file);
125
}
126
 
127
#ifdef __SCLE
128
int
129
_DEFUN(__stextmode, (fd),
130
       int fd)
131
{
132
#ifdef __CYGWIN__
133
  extern int _cygwin_istext_for_stdio (int);
134
  return _cygwin_istext_for_stdio (fd);
135
#else
136
  return 0;
137
#endif
138
}
139
#endif

powered by: WebSVN 2.1.0

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