Rev 4874 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4349 | Serge | 1 | /* |
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 |
||
21 | #include |
||
22 | #include |
||
23 | #include |
||
24 | #include |
||
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 |
||
4921 | Serge | 37 | _READ_WRITE_BUFSIZE_TYPE n) |
4349 | Serge | 38 | { |
39 | register FILE *fp = (FILE *) cookie; |
||
4921 | Serge | 40 | register ssize_t ret; |
4349 | Serge | 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 | /* Dummy function used in sscanf/swscanf. */ |
||
65 | _READ_WRITE_RETURN_TYPE |
||
66 | _DEFUN(__seofread, (ptr, cookie, buf, len), |
||
67 | struct _reent *_ptr _AND |
||
68 | _PTR cookie _AND |
||
69 | char *buf _AND |
||
4921 | Serge | 70 | _READ_WRITE_BUFSIZE_TYPE len) |
4349 | Serge | 71 | { |
72 | return 0; |
||
73 | } |
||
74 | |||
75 | _READ_WRITE_RETURN_TYPE |
||
76 | _DEFUN(__swrite, (ptr, cookie, buf, n), |
||
77 | struct _reent *ptr _AND |
||
78 | void *cookie _AND |
||
79 | char const *buf _AND |
||
4921 | Serge | 80 | _READ_WRITE_BUFSIZE_TYPE n) |
4349 | Serge | 81 | { |
82 | register FILE *fp = (FILE *) cookie; |
||
4921 | Serge | 83 | ssize_t w; |
4349 | Serge | 84 | #ifdef __SCLE |
85 | int oldmode=0; |
||
86 | #endif |
||
87 | |||
88 | if (fp->_flags & __SAPP) |
||
89 | _lseek_r (ptr, fp->_file, (_off_t) 0, SEEK_END); |
||
90 | fp->_flags &= ~__SOFF; /* in case O_APPEND mode is set */ |
||
91 | |||
92 | #ifdef __SCLE |
||
93 | if (fp->_flags & __SCLE) |
||
94 | oldmode = setmode (fp->_file, O_BINARY); |
||
95 | #endif |
||
96 | |||
97 | w = _write_r (ptr, fp->_file, buf, n); |
||
98 | |||
99 | #ifdef __SCLE |
||
100 | if (oldmode) |
||
101 | setmode (fp->_file, oldmode); |
||
102 | #endif |
||
103 | |||
104 | return w; |
||
105 | } |
||
106 | |||
107 | _fpos_t |
||
108 | _DEFUN(__sseek, (ptr, cookie, offset, whence), |
||
109 | struct _reent *ptr _AND |
||
110 | void *cookie _AND |
||
111 | _fpos_t offset _AND |
||
112 | int whence) |
||
113 | { |
||
114 | register FILE *fp = (FILE *) cookie; |
||
115 | register _off_t ret; |
||
116 | |||
117 | ret = _lseek_r (ptr, fp->_file, (_off_t) offset, whence); |
||
118 | if (ret == -1L) |
||
119 | fp->_flags &= ~__SOFF; |
||
120 | else |
||
121 | { |
||
122 | fp->_flags |= __SOFF; |
||
123 | fp->_offset = ret; |
||
124 | } |
||
125 | return ret; |
||
126 | } |
||
127 | |||
128 | int |
||
129 | _DEFUN(__sclose, (ptr, cookie), |
||
130 | struct _reent *ptr _AND |
||
131 | void *cookie) |
||
132 | { |
||
133 | FILE *fp = (FILE *) cookie; |
||
134 | |||
135 | return _close_r (ptr, fp->_file); |
||
136 | } |
||
137 | |||
138 | #ifdef __SCLE |
||
139 | int |
||
140 | _DEFUN(__stextmode, (fd), |
||
141 | int fd) |
||
142 | { |
||
143 | #ifdef __CYGWIN__ |
||
144 | extern int _cygwin_istext_for_stdio (int); |
||
145 | return _cygwin_istext_for_stdio (fd); |
||
146 | #else |
||
147 | return 0; |
||
148 | #endif |
||
149 | } |
||
150 | #endif |