1 |
39 |
lampret |
/*
|
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 |
|
|
* %W% (UofMD/Berkeley) %G%
|
18 |
|
|
*/
|
19 |
|
|
|
20 |
|
|
/*
|
21 |
|
|
* Information local to this implementation of stdio,
|
22 |
|
|
* in particular, macros and private variables.
|
23 |
|
|
*/
|
24 |
|
|
|
25 |
|
|
#include <_ansi.h>
|
26 |
|
|
#include <stdarg.h>
|
27 |
|
|
#include <reent.h>
|
28 |
|
|
#include <unistd.h>
|
29 |
|
|
|
30 |
|
|
extern int _EXFUN(__svfscanf,(FILE *, _CONST char *,va_list));
|
31 |
|
|
extern FILE *_EXFUN(__sfp,(struct _reent *));
|
32 |
|
|
extern int _EXFUN(__sflags,(struct _reent *,_CONST char*, int*));
|
33 |
|
|
extern int _EXFUN(__srefill,(FILE *));
|
34 |
|
|
extern int _EXFUN(__sread,(void *, char *, int));
|
35 |
|
|
extern int _EXFUN(__swrite,(void *, char const *, int));
|
36 |
|
|
extern fpos_t _EXFUN(__sseek,(void *, fpos_t, int));
|
37 |
|
|
extern int _EXFUN(__sclose,(void *));
|
38 |
|
|
extern void _EXFUN(__sinit,(struct _reent *));
|
39 |
|
|
extern void _EXFUN(_cleanup_r,(struct _reent *));
|
40 |
|
|
extern void _EXFUN(__smakebuf,(FILE *));
|
41 |
|
|
extern int _EXFUN(_fwalk,(struct _reent *, int (*)(FILE *)));
|
42 |
|
|
struct _glue * _EXFUN(__sfmoreglue,(struct _reent *,int n));
|
43 |
|
|
extern int _EXFUN(__srefill,(FILE *fp));
|
44 |
|
|
|
45 |
|
|
/* Called by the main entry point fns to ensure stdio has been initialized. */
|
46 |
|
|
|
47 |
|
|
#define CHECK_INIT(fp) \
|
48 |
|
|
do \
|
49 |
|
|
{ \
|
50 |
|
|
if ((fp)->_data == 0) \
|
51 |
|
|
(fp)->_data = _REENT; \
|
52 |
|
|
if (!(fp)->_data->__sdidinit) \
|
53 |
|
|
__sinit ((fp)->_data); \
|
54 |
|
|
} \
|
55 |
|
|
while (0)
|
56 |
|
|
|
57 |
|
|
/* Return true iff the given FILE cannot be written now. */
|
58 |
|
|
|
59 |
|
|
#define cantwrite(fp) \
|
60 |
|
|
((((fp)->_flags & __SWR) == 0 || (fp)->_bf._base == NULL) && \
|
61 |
|
|
__swsetup(fp))
|
62 |
|
|
|
63 |
|
|
/* Test whether the given stdio file has an active ungetc buffer;
|
64 |
|
|
release such a buffer, without restoring ordinary unread data. */
|
65 |
|
|
|
66 |
|
|
#define HASUB(fp) ((fp)->_ub._base != NULL)
|
67 |
|
|
#define FREEUB(fp) { \
|
68 |
|
|
if ((fp)->_ub._base != (fp)->_ubuf) \
|
69 |
|
|
_free_r(fp->_data, (char *)(fp)->_ub._base); \
|
70 |
|
|
(fp)->_ub._base = NULL; \
|
71 |
|
|
}
|
72 |
|
|
|
73 |
|
|
/* Test for an fgetline() buffer. */
|
74 |
|
|
|
75 |
|
|
#define HASLB(fp) ((fp)->_lb._base != NULL)
|
76 |
|
|
#define FREELB(fp) { _free_r(fp->_data,(char *)(fp)->_lb._base); (fp)->_lb._base = NULL; }
|
77 |
|
|
|
78 |
|
|
/* WARNING: _dcvt is defined in the stdlib directory, not here! */
|
79 |
|
|
|
80 |
|
|
char *_EXFUN(_dcvt,(struct _reent *, char *, double, int, int, char, int));
|
81 |
|
|
char *_EXFUN(_sicvt,(char *, short, char));
|
82 |
|
|
char *_EXFUN(_icvt,(char *, int, char));
|
83 |
|
|
char *_EXFUN(_licvt,(char *, long, char));
|
84 |
|
|
#ifdef __GNUC__
|
85 |
|
|
char *_EXFUN(_llicvt,(char *, long long, char));
|
86 |
|
|
#endif
|
87 |
|
|
|
88 |
|
|
#define CVT_BUF_SIZE 128
|
89 |
|
|
|
90 |
|
|
#define NDYNAMIC 4 /* add four more whenever necessary */
|