2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
8 /* Original source from libnix */
10 #include <proto/dos.h>
17 ** If the VFSCANF_DIRECT_DOS define is set to 1, dos.library functions FGetC()
18 ** and UnGetC() are used directly, for possibly better speed. Otherwise
19 ** the clib functions fgetc/ungetc are used.
22 #define VFSCANF_DIRECT_DOS 1
24 #if VFSCANF_DIRECT_DOS
26 struct __vfscanf_handle
32 static int __getc(void *_h
);
33 static int __ungetc(int c
, void *_h
);
37 /*****************************************************************************
50 Read the scream, scan it as the format specified and write the
51 result of the conversion into the specified arguments.
54 stream - A stream to read from
55 format - A scanf() format string.
56 args - A list of arguments for the results.
59 The number of converted arguments.
71 ******************************************************************************/
73 #if VFSCANF_DIRECT_DOS
74 struct __vfscanf_handle h
;
77 h
.fdesc
= __getfdesc(stream
->fd
);
86 Flush (h
.fdesc
->fcb
->handle
);
88 return __vcscan (&h
, __getc
, __ungetc
, format
, args
);
92 fdesc
= __getfdesc(stream
->fd
);
100 Flush (fdesc
->fcb
->handle
);
102 return __vcscan (stream
, fgetc
, ungetc
, format
, args
);
107 #if VFSCANF_DIRECT_DOS
109 static int __ungetc(int c
, void *_h
)
111 struct __vfscanf_handle
*h
= _h
;
112 /* Note: changes here might require changes in ungetc.c!! */
117 if (!UnGetC(h
->fdesc
->fcb
->handle
, c
))
119 errno
= __stdc_ioerr2errno(IoErr());
123 h
->stream
->flags
|= __POSIXC_STDIO_ERROR
;
127 h
->stream
->flags
|= __POSIXC_STDIO_EOF
;
136 static int __getc(void *_h
)
138 struct __vfscanf_handle
*h
= _h
;
139 fdesc
*fdesc
= h
->fdesc
;
142 /* Note: changes here might require changes in fgetc.c!! */
146 c
= FGetC(h
->fdesc
->fcb
->handle
);
154 errno
= __stdc_ioerr2errno(c
);
155 h
->stream
->flags
|= __POSIXC_STDIO_ERROR
;
159 h
->stream
->flags
|= __POSIXC_STDIO_EOF
;