2 * Copyright (c) 1990 The Regents of the University of California.
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 * and/or 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.
17 /* No user fns here. Pesch 15apr92. */
22 #include <sys/types.h>
24 #include <sys/unistd.h>
28 * Small standard I/O/seek/close functions.
29 * These maintain the `known seek offset' for seek optimisation.
32 _READ_WRITE_RETURN_TYPE
33 __sread (struct _reent
*ptr
,
36 _READ_WRITE_BUFSIZE_TYPE n
)
38 register FILE *fp
= (FILE *) cookie
;
43 if (fp
->_flags
& __SCLE
)
44 oldmode
= setmode (fp
->_file
, O_BINARY
);
47 ret
= _read_r (ptr
, fp
->_file
, buf
, n
);
51 setmode (fp
->_file
, oldmode
);
54 /* If the read succeeded, update the current offset. */
59 fp
->_flags
&= ~__SOFF
; /* paranoia */
63 /* Dummy function used in sscanf/swscanf. */
64 _READ_WRITE_RETURN_TYPE
65 __seofread (struct _reent
*_ptr
,
68 _READ_WRITE_BUFSIZE_TYPE len
)
73 _READ_WRITE_RETURN_TYPE
74 __swrite (struct _reent
*ptr
,
77 _READ_WRITE_BUFSIZE_TYPE n
)
79 register FILE *fp
= (FILE *) cookie
;
85 if (fp
->_flags
& __SAPP
)
86 _lseek_r (ptr
, fp
->_file
, (_off_t
) 0, SEEK_END
);
87 fp
->_flags
&= ~__SOFF
; /* in case O_APPEND mode is set */
90 if (fp
->_flags
& __SCLE
)
91 oldmode
= setmode (fp
->_file
, O_BINARY
);
94 w
= _write_r (ptr
, fp
->_file
, buf
, n
);
98 setmode (fp
->_file
, oldmode
);
105 __sseek (struct _reent
*ptr
,
110 register FILE *fp
= (FILE *) cookie
;
113 ret
= _lseek_r (ptr
, fp
->_file
, (_off_t
) offset
, whence
);
115 fp
->_flags
&= ~__SOFF
;
118 fp
->_flags
|= __SOFF
;
125 __sclose (struct _reent
*ptr
,
128 FILE *fp
= (FILE *) cookie
;
130 return _close_r (ptr
, fp
->_file
);
138 extern int _cygwin_istext_for_stdio (int);
139 return _cygwin_istext_for_stdio (fd
);