Don't call ReadArgs() if started from WB.
[tangerine.git] / compiler / clib / vfscanf.c
blobc2c53b2a0df2bb463f128899ba426657dd530f00
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Scan a stream and write the result in the parameters.
6 */
8 /* Original source from libnix */
10 #include <proto/dos.h>
11 #include <errno.h>
12 #include "__errno.h"
13 #include "__open.h"
14 #include <stdio.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
28 FILE *stream;
29 fdesc *fdesc;
32 static int __getc(void *_h);
33 static int __ungetc(int c, void *_h);
35 #endif
37 /*****************************************************************************
39 NAME */
40 #include <stdarg.h>
42 int vfscanf (
44 /* SYNOPSIS */
45 FILE * stream,
46 const char * format,
47 va_list args)
49 /* FUNCTION
50 Read the scream, scan it as the format specified and write the
51 result of the conversion into the specified arguments.
53 INPUTS
54 stream - A stream to read from
55 format - A scanf() format string.
56 args - A list of arguments for the results.
58 RESULT
59 The number of converted arguments.
61 NOTES
63 EXAMPLE
65 BUGS
67 SEE ALSO
69 INTERNALS
71 ******************************************************************************/
73 #if VFSCANF_DIRECT_DOS
74 struct __vfscanf_handle h;
76 h.stream = stream;
77 h.fdesc = __getfdesc(stream->fd);
79 if (!h.fdesc)
81 errno = EBADF;
82 return 0;
86 Flush (h.fdesc->fh);
88 return __vcscan (&h, __getc, __ungetc, format, args);
89 #else
90 fdesc *fdesc;
92 fdesc = __getfdesc(stream->fd);
94 if (!fdesc)
96 errno = EBADF;
97 return 0;
100 Flush (fdesc->fh);
102 return __vcscan (stream, fgetc, ungetc, format, args);
104 #endif
105 } /* vfscanf */
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!! */
114 if (c < -1)
115 c = (unsigned int)c;
117 if (!UnGetC((BPTR)h->fdesc->fh, c))
119 errno = IoErr2errno(IoErr());
121 if (errno)
123 h->stream->flags |= _STDIO_ERROR;
125 else
127 h->stream->flags |= _STDIO_EOF;
130 c = EOF;
133 return c;
136 static int __getc(void *_h)
138 struct __vfscanf_handle *h = _h;
139 int c;
141 /* Note: changes here might require changes in fgetc.c!! */
143 c = FGetC((BPTR)h->fdesc->fh);
145 if (c == EOF)
147 c = IoErr();
149 if (c)
151 errno = IoErr2errno(c);
152 h->stream->flags |= _STDIO_ERROR;
154 else
156 h->stream->flags |= _STDIO_EOF;
159 c = EOF;
162 return c;
165 #endif