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