|
1 /* LOCAL.H |
|
2 * |
|
3 * Portions Copyright (c) 1990-1999 Nokia Corporation and/or its subsidiary(-ies). |
|
4 * All rights reserved. |
|
5 */ |
|
6 |
|
7 /* |
|
8 * Copyright (c) 1990 The Regents of the University of California. |
|
9 * All rights reserved. |
|
10 * |
|
11 * Redistribution and use in source and binary forms are permitted |
|
12 * provided that the above copyright notice and this paragraph are |
|
13 * duplicated in all such forms and that any documentation, |
|
14 * advertising materials, and other materials related to such |
|
15 * distribution and use acknowledge that the software was developed |
|
16 * by the University of California, Berkeley. The name of the |
|
17 * University may not be used to endorse or promote products derived |
|
18 * from this software without specific prior written permission. |
|
19 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR |
|
20 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED |
|
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
|
22 * |
|
23 * %W% (UofMD/Berkeley) %G% |
|
24 */ |
|
25 |
|
26 /* |
|
27 * Information local to this implementation of stdio, |
|
28 * in particular, macros and private variables. |
|
29 */ |
|
30 |
|
31 #include <_ansi.h> |
|
32 #include <stdarg.h> |
|
33 #include <reent.h> |
|
34 #include <unistd.h> |
|
35 /** |
|
36 @internalComponent |
|
37 */ |
|
38 extern int __svfscanf (FILE *, const char *,va_list); |
|
39 extern FILE* __sfp (struct _reent *); |
|
40 extern int __sflags (struct _reent *,const wchar_t*, int*); |
|
41 extern int __srefill (FILE *); |
|
42 extern int __sread (void *, char *, int); |
|
43 extern int __swrite (void *, char const *, int); |
|
44 extern fpos_t __sseek (void *, fpos_t, int); |
|
45 extern int __sclose (void *); |
|
46 extern void __sinit (struct _reent *); |
|
47 extern void __smakebuf (FILE *); |
|
48 extern int _fwalk (struct _reent *, int (*)(FILE *)); |
|
49 struct _glue* __sfmoreglue (struct _reent *,int n); |
|
50 extern int __srefill (FILE *fp); |
|
51 extern int __srget (FILE *fp); |
|
52 extern int __swbuf (int c, FILE *fp); |
|
53 |
|
54 /** |
|
55 Macros used inside the implementation of STDIO. These used to be in |
|
56 the <stdio.h> include file, but we want to hide them as much as |
|
57 possible to give us a change to change the implementation if |
|
58 necessary. |
|
59 @internalComponent |
|
60 */ |
|
61 #define __sfeof(p) (((p)->_flags & __SEOF) != 0) |
|
62 #define __sferror(p) (((p)->_flags & __SERR) != 0) |
|
63 #define __sclearerr(p) ((void)((p)->_flags &= ~(__SERR|__SEOF))) |
|
64 #define __sfileno(p) ((p)->_file) |
|
65 /** |
|
66 @internalComponent |
|
67 */ |
|
68 #define feof(p) __sfeof(p) |
|
69 #define ferror(p) __sferror(p) |
|
70 #define clearerr(p) __sclearerr(p) |
|
71 /** |
|
72 @internalComponent |
|
73 */ |
|
74 #define __sgetc(p) (--(p)->_r < 0 ? __srget(p) : (int)(*(p)->_p++)) |
|
75 #define __sputc(c, p) \ |
|
76 (--(p)->_w < 0 ? \ |
|
77 (p)->_w >= (p)->_lbfsize ? \ |
|
78 (*(p)->_p = (unsigned char)(c)), *(p)->_p != '\n' ? \ |
|
79 (int)*(p)->_p++ : \ |
|
80 __swbuf('\n', p) : \ |
|
81 __swbuf((int)(c), p) : \ |
|
82 (*(p)->_p = (unsigned char)(c), (int)*(p)->_p++)) |
|
83 |
|
84 /** |
|
85 Called by the main entry point fns to ensure stdio has been initialized. |
|
86 @internalComponent |
|
87 */ |
|
88 #define CHECK_INIT(fp) /* done in the construction of the struct _reent */ |
|
89 /* |
|
90 #define CHECK_INIT(fp) \ |
|
91 { \ |
|
92 if ((fp)->_data == 0) \ |
|
93 (fp)->_data = _REENT; \ |
|
94 if (!(fp)->_data->__sdidinit) \ |
|
95 __sinit ((fp)->_data); \ |
|
96 } |
|
97 */ |
|
98 |
|
99 /** |
|
100 Return true iff the given FILE cannot be written now. |
|
101 @internalComponent |
|
102 */ |
|
103 #define cantwrite(fp) \ |
|
104 ((((fp)->_flags & __SWR) == 0 || (fp)->_bf._base == NULL) && \ |
|
105 __swsetup(fp)) |
|
106 |
|
107 /** |
|
108 Test whether the given stdio file has an active ungetc buffer; |
|
109 release such a buffer, without restoring ordinary unread data. |
|
110 @internalComponent |
|
111 */ |
|
112 #define HASUB(fp) ((fp)->_ub._base != NULL) |
|
113 #define FREEUB(fp) { \ |
|
114 if ((fp)->_ub._base != (fp)->_ubuf) \ |
|
115 _free_r(fp->_data, (char *)(fp)->_ub._base); \ |
|
116 (fp)->_ub._base = NULL; \ |
|
117 } |
|
118 |
|
119 /** |
|
120 Test for an fgetline() buffer. |
|
121 @internalComponent |
|
122 */ |
|
123 #define HASLB(fp) ((fp)->_lb._base != NULL) |
|
124 #define FREELB(fp) { _free_r(fp->_data,(char *)(fp)->_lb._base); (fp)->_lb._base = NULL; } |
|
125 |
|
126 /* |
|
127 WARNING: _dcvt is defined in the stdlib directory, not here! |
|
128 @internalComponent |
|
129 */ |
|
130 char *_dcvt (struct _reent *, char *, double, int, int, char, int); |
|
131 char *_sicvt (char *, short, char); |
|
132 char *_icvt (char *, int, char); |
|
133 char *_licvt (char *, long, char); |
|
134 #ifdef __GNUC__ |
|
135 char *_llicvt (char *, long long, char); |
|
136 #endif |
|
137 /** |
|
138 @internalComponent |
|
139 */ |
|
140 #define CVT_BUF_SIZE 128 |
|
141 /** |
|
142 @internalComponent |
|
143 */ |
|
144 #define NDYNAMIC 4 /* add four more whenever necessary */ |