1 /* Copyright (C) 2004-2005 Manuel Novoa III <mjn3@codepoet.org>
2 *
3 * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
4 *
5 * Dedicated to Toni. See uClibc/DEDICATION.mjn3 for details.
6 */
7
8 #include "_stdio.h"
9
10 /**********************************************************************/
11 #ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
12 /**********************************************************************/
13
_cs_read(void * cookie,char * buf,size_t bufsize)14 ssize_t attribute_hidden _cs_read(void *cookie, char *buf, size_t bufsize)
15 {
16 return read(*((int *) cookie), buf, bufsize);
17 }
18
19 /**********************************************************************/
20
_cs_write(void * cookie,const char * buf,size_t bufsize)21 ssize_t attribute_hidden _cs_write(void *cookie, const char *buf, size_t bufsize)
22 {
23 return write(*((int *) cookie), (char *) buf, bufsize);
24 }
25
26 /**********************************************************************/
27
_cs_seek(void * cookie,register __offmax_t * pos,int whence)28 int attribute_hidden _cs_seek(void *cookie, register __offmax_t *pos, int whence)
29 {
30 __offmax_t res;
31
32 #ifdef __UCLIBC_HAS_LFS__
33 res = lseek64(*((int *) cookie), *pos, whence);
34 #else
35 res = lseek(*((int *) cookie), *pos, whence);
36 #endif
37
38 return (res >= 0) ? ((*pos = res), 0) : ((int) res);
39 }
40
41 /**********************************************************************/
42
_cs_close(void * cookie)43 int attribute_hidden _cs_close(void *cookie)
44 {
45 return close(*((int *) cookie));
46 }
47
48 /**********************************************************************/
49 #else
50 /**********************************************************************/
51
__stdio_seek(FILE * stream,register __offmax_t * pos,int whence)52 int attribute_hidden __stdio_seek(FILE *stream, register __offmax_t *pos, int whence)
53 {
54 __offmax_t res;
55
56 #ifdef __UCLIBC_HAS_LFS__
57 res = lseek64(stream->__filedes, *pos, whence);
58 #else
59 res = lseek(stream->__filedes, *pos, whence);
60 #endif
61
62 return (res >= 0) ? ((*pos = res), 0) : ((int) res);
63 }
64
65 /**********************************************************************/
66 #endif
67 /**********************************************************************/
68