xref: /titanic_50/usr/src/lib/libast/common/features/stdio (revision ed5289f91b9bf164dccd6c75398362be77a4478d)
1set	prototyped
2ref	-D_def_map_ast=1
3iff	SFSTDIO
4cat{
5	#define __FILE_typedef	1
6	#define _FILE_DEFINED	1
7	#define _FILE_defined	1
8	#define _FILEDEFED	1
9
10	#ifndef __FILE_TAG
11	#define __FILE_TAG	_sfio_s
12	#endif
13
14	#undef	FILE
15	#undef	_FILE
16	#undef	fpos_t
17	#undef	fpos64_t
18
19	typedef struct _sfio_s _sfio_FILE;
20
21	#define FILE		_sfio_FILE
22	#define _FILE		FILE
23
24	#if !defined(__FILE) && !__CYGWIN__
25	#undef	__FILE
26	#define __FILE		FILE
27	#endif
28
29	#if defined(_AST_H) || defined(_SFIO_H)
30
31	#define BUFSIZ		SF_BUFSIZE
32
33	#else
34
35	#ifndef BUFSIZ
36	#define BUFSIZ		8192
37	#endif
38
39	#ifndef EOF
40	#define EOF		(-1)
41	#endif
42
43	#ifndef NULL
44	#define NULL		0
45	#endif
46
47	#ifndef SEEK_SET
48	#define SEEK_SET	0
49	#define SEEK_CUR	1
50	#define SEEK_END	2
51	#endif
52
53	#include <ast_std.h>
54
55	#include <sfio_s.h>
56
57	#if __cplusplus
58	#define _sf_(f)		(f)
59	#else
60	#define _sf_(f)		((struct _sfio_s*)(f))
61	#endif
62
63	#define _SF_EOF		0000200
64	#define _SF_ERROR	0000400
65
66	#endif
67
68	#ifdef _NO_LARGEFILE64_SOURCE
69	#undef _LARGEFILE64_SOURCE
70	#endif
71
72	#ifdef _LARGEFILE64_SOURCE
73	#undef	off_t
74	#endif
75
76	#define fpos_t		_ast_fpos_t
77	#if _typ_int64_t
78	#define fpos64_t	_ast_fpos_t
79	#endif
80
81	typedef struct _ast_fpos_s
82	{
83		intmax_t	_sf_offset;
84		unsigned char	_sf_state[64 - sizeof(intmax_t)];
85	} _ast_fpos_t;
86
87	#define _base		_data
88	#define _ptr		_next
89	#define _IOFBF		0
90	#define _IONBF		1
91	#define _IOLBF		2
92
93	#if defined(__cplusplus) && defined(__THROW) && !defined(_UWIN)
94
95	#undef	FILE
96	#define FILE            FILE
97	typedef struct _sfio_s FILE;
98
99	#undef	strerror
100	extern char*	strerror(int) __THROW;
101
102	extern int	_doprnt(const char*, va_list, FILE*);
103	extern int	_doscan(FILE*, const char*, va_list);
104	extern int	asprintf(char**, const char*, ...);
105	extern int	clearerr(FILE*);
106	extern int	fclose(FILE*);
107	extern FILE*	fdopen(int, const char*);
108	extern int	feof(FILE*);
109	extern int	ferror(FILE*);
110	extern int	fflush(FILE*);
111	extern int	fgetc(FILE*);
112	extern int	fgetpos(FILE*, fpos_t*);
113	extern char*	fgets(char*, int, FILE*);
114	extern int	fileno(FILE*);
115	extern FILE*	fopen(const char*, const char*);
116	extern int	fprintf(FILE*, const char*, ...);
117	extern int	fpurge(FILE*);
118	extern int	fputc(int, FILE*);
119	extern int	fputs(const char*, FILE*);
120	extern ssize_t	fread(void*, size_t, size_t, FILE*);
121	extern FILE*	freopen(const char*, const char*, FILE*);
122	extern int	fscanf(FILE*, const char*, ...);
123	extern int	fseek(FILE*, long, int);
124	extern int	fseeko(FILE*, off_t, int);
125	extern int	fsetpos(FILE*, const fpos_t*);
126	extern long	ftell(FILE*);
127	extern off_t	ftello(FILE*);
128	extern ssize_t	fwrite(const void*, size_t, size_t, FILE*);
129	extern int	getc(FILE*);
130	extern int	getchar(void);
131	extern char*	gets(char*);
132	extern int	getw(FILE*);
133	extern int	pclose(FILE*);
134	extern FILE*	popen(const char*, const char*);
135	extern int	printf(const char*, ...);
136	extern int	putc(int, FILE*);
137	extern int	putchar(int);
138	extern int	puts(const char*);
139	extern int	putw(int, FILE*);
140	extern void	rewind(FILE*);
141	extern int	scanf(const char*, ...);
142	extern void	setbuf(FILE*, char*);
143	extern int	setbuffer(FILE*, char*, int);
144	extern int	setlinebuf(FILE*);
145	extern int	setvbuf(FILE*, char*, int, size_t);
146	extern int	snprintf(char*, int, const char*, ...);
147	extern int	sprintf(char*, const char*, ...);
148	extern int	sscanf(const char*, const char*, ...);
149	extern FILE*	tmpfile(void);
150	extern int	ungetc(int, FILE*);
151	extern int	vasprintf(char**, const char*, va_list);
152	extern int	vfprintf(FILE*, const char*, va_list);
153	extern int	vfscanf(FILE*, const char*, va_list);
154	extern int	vprintf(const char*, va_list);
155	extern int	vscanf(const char*, va_list);
156	extern int	vsnprintf(char*, int, const char*, va_list);
157	extern int	vsprintf(char*, const char*, va_list);
158	extern int	vsscanf(const char*, const char*, va_list);
159
160	#if _typ_int64_t
161
162	extern int		fgetpos64(FILE*, fpos64_t*);
163	extern int		fsetpos64(FILE*, const fpos64_t*);
164	extern int		fseek64(FILE*, int64_t, int);
165	extern int		fseeko64(FILE*, int64_t, int);
166	extern int64_t		ftell64(FILE*);
167	extern int64_t		ftello64(FILE*);
168
169	#endif
170
171	extern void	clearerr_unlocked(FILE*);
172	extern int	feof_unlocked(FILE*);
173	extern int	ferror_unlocked(FILE*);
174	extern int	fflush_unlocked(FILE*);
175	extern int	fgetc_unlocked(FILE*);
176	extern char*	fgets_unlocked(char*, int, FILE*);
177	extern int	fileno_unlocked(FILE*);
178	extern int	fputc_unlocked(int, FILE*);
179	extern int	fputs_unlocked(char*, FILE*);
180	extern size_t	fread_unlocked(void*, size_t, size_t, FILE*);
181	extern size_t	fwrite_unlocked(void*, size_t, size_t, FILE*);
182	extern int	getc_unlocked(FILE*);
183	extern int	getchar_unlocked(void);
184	extern int	putc_unlocked(int, FILE*);
185	extern int	putchar_unlocked(int);
186
187	#ifdef _USE_GNU
188
189	extern int	fcloseall(void);
190	extern FILE*	fmemopen(void*, size_t, const char*);
191	extern ssize_t	__getdelim(char**, size_t*, int, FILE*);
192	extern ssize_t	getdelim(char**, size_t*, int, FILE*);
193	extern ssize_t	getline(char**, size_t*, FILE*);
194
195	#endif
196
197	#endif
198}end
199output{
200	#include <stdio.h>
201	#ifndef FILENAME_MAX
202	#ifndef NAME_MAX
203	#ifndef _POSIX_NAME_MAX
204	#define _POSIX_NAME_MAX	14
205	#endif
206	#define NAME_MAX	_POSIX_NAME_MAX
207	#endif
208	#define FILENAME_MAX	NAME_MAX
209	#endif
210	#ifndef FOPEN_MAX
211	#ifdef STREAM_MAX
212	#define FOPEN_MAX	STREAM_MAX
213	#else
214	#ifndef OPEN_MAX
215	#ifndef _POSIX_OPEN_MAX
216	#define _POSIX_OPEN_MAX	20
217	#endif
218	#define OPEN_MAX	_POSIX_OPEN_MAX
219	#endif
220	#define FOPEN_MAX	OPEN_MAX
221	#endif
222	#endif
223	#ifndef TMP_MAX
224	#define TMP_MAX		33520641
225	#endif
226	int
227	main()
228	{
229		printf("#ifndef FILENAME_MAX\n");
230		printf("#define FILENAME_MAX	%d\n", FILENAME_MAX);
231		printf("#endif\n");
232		printf("#ifndef FOPEN_MAX\n");
233		printf("#define FOPEN_MAX	%d\n", FOPEN_MAX);
234		printf("#endif\n");
235		printf("#ifndef TMP_MAX\n");
236		printf("#define TMP_MAX		%d\n", TMP_MAX);
237		printf("#endif\n");
238	#if !_UWIN
239		printf("\n");
240		printf("#define _doprnt		_ast_doprnt\n");
241		printf("#define _doscan		_ast_doscan\n");
242		printf("#define asprintf	_ast_asprintf\n");
243		printf("#define clearerr	_ast_clearerr\n");
244		printf("#define fclose		_ast_fclose\n");
245		printf("#define fdopen		_ast_fdopen\n");
246		printf("#define fflush		_ast_fflush\n");
247		printf("#define fgetc		_ast_fgetc\n");
248		printf("#define fgetpos		_ast_fgetpos\n");
249		printf("#define fgetpos64	_ast_fgetpos64\n");
250		printf("#define fgets		_ast_fgets\n");
251		printf("#define fopen		_ast_fopen\n");
252		printf("#define fprintf		_ast_fprintf\n");
253		printf("#define fpurge		_ast_fpurge\n");
254		printf("#define fputs		_ast_fputs\n");
255		printf("#define fread		_ast_fread\n");
256		printf("#define freopen		_ast_freopen\n");
257		printf("#define fscanf		_ast_fscanf\n");
258		printf("#define fseek		_ast_fseek\n");
259		printf("#define fseek64		_ast_fseek64\n");
260		printf("#define fseeko		_ast_fseeko\n");
261		printf("#define fseeko64	_ast_fseeko64\n");
262		printf("#define fsetpos		_ast_fsetpos\n");
263		printf("#define fsetpos64	_ast_fsetpos64\n");
264		printf("#define ftell		_ast_ftell\n");
265		printf("#define ftell64		_ast_ftell64\n");
266		printf("#define ftello		_ast_ftello\n");
267		printf("#define ftello64	_ast_ftello64\n");
268		printf("#define fwrite		_ast_fwrite\n");
269		printf("#define gets		_ast_gets\n");
270		printf("#define getw		_ast_getw\n");
271		printf("#define pclose		_ast_pclose\n");
272		printf("#define popen		_ast_popen\n");
273		printf("#define printf		_ast_printf\n");
274		printf("#define puts		_ast_puts\n");
275		printf("#define putw		_ast_putw\n");
276		printf("#define rewind		_ast_rewind\n");
277		printf("#define scanf		_ast_scanf\n");
278		printf("#define setbuf		_ast_setbuf\n");
279		printf("#undef	setbuffer\n");
280		printf("#define setbuffer	_ast_setbuffer\n");
281		printf("#define setlinebuf	_ast_setlinebuf\n");
282		printf("#define setvbuf		_ast_setvbuf\n");
283		printf("#define snprintf	_ast_snprintf\n");
284		printf("#define sprintf		_ast_sprintf\n");
285		printf("#define sscanf		_ast_sscanf\n");
286		printf("#define tmpfile		_ast_tmpfile\n");
287		printf("#define ungetc		_ast_ungetc\n");
288		printf("#define vasprintf	_ast_vasprintf\n");
289		printf("#define vfprintf	_ast_vfprintf\n");
290		printf("#define vfscanf		_ast_vfscanf\n");
291		printf("#define vprintf		_ast_vprintf\n");
292		printf("#define vscanf		_ast_vscanf\n");
293		printf("#define vsnprintf	_ast_vsnprintf\n");
294		printf("#define vsprintf	_ast_vsprintf\n");
295		printf("#define vsscanf		_ast_vsscanf\n");
296
297		printf("#define fcloseall	_ast_fcloseall\n");
298		printf("#define fmemopen	_ast_fmemopen\n");
299		printf("#define __getdelim	_ast___getdelim\n");
300		printf("#define getdelim	_ast_getdelim\n");
301		printf("#define getline		_ast_getline\n");
302
303		printf("#define clearerr_unlocked _ast_clearerr_unlocked\n");
304		printf("#define feof_unlocked	_ast_feof_unlocked\n");
305		printf("#define ferror_unlocked	_ast_ferror_unlocked\n");
306		printf("#define fflush_unlocked	_ast_fflush_unlocked\n");
307		printf("#define fgetc_unlocked	_ast_fgetc_unlocked\n");
308		printf("#define fgets_unlocked	_ast_fgets_unlocked\n");
309		printf("#define fileno_unlocked	_ast_fileno_unlocked\n");
310		printf("#define fputc_unlocked	_ast_fputc_unlocked\n");
311		printf("#define fputs_unlocked	_ast_fputs_unlocked\n");
312		printf("#define fread_unlocked	_ast_fread_unlocked\n");
313		printf("#define fwrite_unlocked	_ast_fwrite_unlocked\n");
314		printf("#define getc_unlocked	_ast_getc_unlocked\n");
315		printf("#define getchar_unlocked _ast_getchar_unlocked\n");
316		printf("#define putc_unlocked	_ast_putc_unlocked\n");
317		printf("#define putchar_unlocked _ast_putchar_unlocked\n");
318
319		printf("\n");
320	#endif
321		return 0;
322	}
323}end
324macro{
325	<<"#if defined(__STDPP__directive) && defined(__STDPP__initial)">>
326	<<"__STDPP__directive pragma pp:initial">>
327	<<"#endif">>
328	<<"#ifndef P_tmpdir">>
329	#ifndef P_tmpdir
330	#define P_tmpdir "/usr/tmp/"
331	#endif
332	<<"#define P_tmpdir">> P_tmpdir <<"/*NOCATLITERAL*/">>
333	<<"#endif">>
334	<<"#ifndef L_ctermid">>
335	#ifndef L_ctermid
336	#define L_ctermid 9
337	#endif
338	<<"#define L_ctermid">> L_ctermid
339	<<"#endif">>
340	<<"#ifndef L_tmpnam">>
341	#ifndef L_tmpnam
342	#define L_tmpnam (sizeof(P_tmpdir)+15)
343	#endif
344	<<"#define L_tmpnam">> L_tmpnam
345	<<"#endif">>
346	<<"#if defined(__STDPP__directive) && defined(__STDPP__initial)">>
347	<<"__STDPP__directive pragma pp:noinitial">>
348	<<"#endif">>
349}end
350cat{
351	#if defined(__cplusplus) && defined(__THROW)
352	extern char*	ctermid(char*) __THROW;
353	#else
354	extern char*	ctermid(char*);
355	#endif
356	extern char*	tmpnam(char*);
357	extern char*	tempnam(const char*, const char*);
358	extern void	perror(const char*);
359	#ifndef _AST_STD_H
360	#ifndef remove
361	extern int	remove(const char*);
362	#endif
363	#ifndef rename
364	extern int	rename(const char*, const char*);
365	#endif
366	#endif
367
368	#undef	extern
369
370	#if _BLD_ast && defined(__EXPORT__)
371	#define extern		__EXPORT__
372	#endif
373
374	extern int	_doprnt(const char*, va_list, FILE*);
375	extern int	_doscan(FILE*, const char*, va_list);
376	extern int	asprintf(char**, const char*, ...);
377	extern int	clearerr(FILE*);
378	extern int	fclose(FILE*);
379	extern FILE*	fdopen(int, const char*);
380	extern int	feof(FILE*);
381	extern int	ferror(FILE*);
382	extern int	fflush(FILE*);
383	extern int	fgetc(FILE*);
384	extern int	fgetpos(FILE*, fpos_t*);
385	extern char*	fgets(char*, int, FILE*);
386	extern int	fileno(FILE*);
387	extern FILE*	fopen(const char*, const char*);
388	extern int	fprintf(FILE*, const char*, ...);
389	extern int	fpurge(FILE*);
390	extern int	fputc(int, FILE*);
391	extern int	fputs(const char*, FILE*);
392	extern ssize_t	fread(void*, size_t, size_t, FILE*);
393	extern FILE*	freopen(const char*, const char*, FILE*);
394	extern int	fscanf(FILE*, const char*, ...);
395	extern int	fseek(FILE*, long, int);
396	extern int	fseeko(FILE*, off_t, int);
397	extern int	fsetpos(FILE*, const fpos_t*);
398	extern long	ftell(FILE*);
399	extern off_t	ftello(FILE*);
400	extern ssize_t	fwrite(const void*, size_t, size_t, FILE*);
401	extern int	getc(FILE*);
402	extern int	getchar(void);
403	extern char*	gets(char*);
404	extern int	getw(FILE*);
405	extern int	pclose(FILE*);
406	extern FILE*	popen(const char*, const char*);
407	extern int	printf(const char*, ...);
408	extern int	putc(int, FILE*);
409	extern int	putchar(int);
410	extern int	puts(const char*);
411	extern int	putw(int, FILE*);
412	extern void	rewind(FILE*);
413	extern int	scanf(const char*, ...);
414	extern void	setbuf(FILE*, char*);
415	extern int	setbuffer(FILE*, char*, int);
416	extern int	setlinebuf(FILE*);
417	extern int	setvbuf(FILE*, char*, int, size_t);
418	extern int	snprintf(char*, int, const char*, ...);
419	extern int	sprintf(char*, const char*, ...);
420	extern int	sscanf(const char*, const char*, ...);
421	extern FILE*	tmpfile(void);
422	extern int	ungetc(int, FILE*);
423	extern int	vasprintf(char**, const char*, va_list);
424	extern int	vfprintf(FILE*, const char*, va_list);
425	extern int	vfscanf(FILE*, const char*, va_list);
426	extern int	vprintf(const char*, va_list);
427	extern int	vscanf(const char*, va_list);
428	extern int	vsnprintf(char*, int, const char*, va_list);
429	extern int	vsprintf(char*, const char*, va_list);
430	extern int	vsscanf(const char*, const char*, va_list);
431
432	#if _typ_int64_t
433
434	extern int		fgetpos64(FILE*, fpos64_t*);
435	extern int		fsetpos64(FILE*, const fpos64_t*);
436	extern int		fseek64(FILE*, int64_t, int);
437	extern int		fseeko64(FILE*, int64_t, int);
438	extern int64_t		ftell64(FILE*);
439	extern int64_t		ftello64(FILE*);
440
441	#ifdef _LARGEFILE64_SOURCE
442
443	#undef	fpos_t
444	#undef	off_t
445	#undef	fgetpos
446	#undef	fsetpos
447	#undef	fseek
448	#undef	fseeko
449	#undef	ftell
450	#undef	ftello
451
452	#define	fpos_t		fpos64_t
453	#if _typ_off64_t
454	#define	off_t		off64_t
455	#else
456	#define	off_t		int64_t
457	#endif
458
459	#define fgetpos		fgetpos64
460	#define fsetpos		fsetpos64
461	#define	fseek		fseek64
462	#define	fseeko		fseeko64
463	#define ftell		ftell64
464	#define ftello		ftello64
465
466	#endif
467
468	#endif
469
470	extern void	clearerr_unlocked(FILE*);
471	extern int	feof_unlocked(FILE*);
472	extern int	ferror_unlocked(FILE*);
473	extern int	fflush_unlocked(FILE*);
474	extern int	fgetc_unlocked(FILE*);
475	extern char*	fgets_unlocked(char*, int, FILE*);
476	extern int	fileno_unlocked(FILE*);
477	extern int	fputc_unlocked(int, FILE*);
478	extern int	fputs_unlocked(char*, FILE*);
479	extern size_t	fread_unlocked(void*, size_t, size_t, FILE*);
480	extern size_t	fwrite_unlocked(void*, size_t, size_t, FILE*);
481	extern int	getc_unlocked(FILE*);
482	extern int	getchar_unlocked(void);
483	extern int	putc_unlocked(int, FILE*);
484	extern int	putchar_unlocked(int);
485
486	#ifdef _USE_GNU
487
488	extern int	fcloseall(void);
489	extern FILE*	fmemopen(void*, size_t, const char*);
490	extern ssize_t	__getdelim(char**, size_t*, int, FILE*);
491	extern ssize_t	getdelim(char**, size_t*, int, FILE*);
492	extern ssize_t	getline(char**, size_t*, FILE*);
493
494	#endif
495
496	#undef	extern
497
498	#if _BLD_DLL && _DLL_INDIRECT_DATA
499
500	#define stdin		((FILE*)_ast_dll->_ast_stdin)
501	#define stdout		((FILE*)_ast_dll->_ast_stdout)
502	#define stderr		((FILE*)_ast_dll->_ast_stderr)
503
504	#else
505
506	#define	stdin		(&_Sfstdin)
507	#define	stdout		(&_Sfstdout)
508	#define	stderr		(&_Sfstderr)
509
510	#endif
511
512	#if defined(_AST_H) || defined(_SFIO_H)
513
514	#define feof(f)		sfeof(f)
515	#define ferror(f)	sferror(f)
516	#define fileno(f)	sffileno(f)
517	#define fputc(c,f)	sfputc(f,c)
518	#define getc(f)		sfgetc(f)
519	#define getchar()	sfgetc(sfstdin)
520	#define putc(c,f)	sfputc(f,c)
521	#define putchar(c)	sfputc(sfstdout,c)
522
523	#else
524
525	#if !_UWIN
526	#if _BLD_ast && defined(__EXPORT__)
527	#define extern		extern __EXPORT__
528	#endif
529	#if !_BLD_ast && defined(__IMPORT__)
530	#define extern		extern __IMPORT__
531	#endif
532	#endif
533
534	extern FILE	_Sfstdin;
535	extern FILE	_Sfstdout;
536	extern FILE	_Sfstderr;
537
538	#undef	extern
539
540	#define feof(f)		(_sf_(f)->_flags&_SF_EOF)
541	#define ferror(f)	(_sf_(f)->_flags&_SF_ERROR)
542	#define fileno(f)	(_sf_(f)->_file)
543	#define fputc(c,f)	(_sf_(f)->_next>=_sf_(f)->_endw?_sfflsbuf(_sf_(f),(int)((unsigned char)(c))):(int)(*_sf_(f)->_next++=(unsigned char)(c)))
544	#define getc(f)		(_sf_(f)->_next>=_sf_(f)->_endr?_sffilbuf(_sf_(f),0):(int)(*_sf_(f)->_next++))
545	#define getchar()	getc(stdin)
546	#define putc(c,f)	fputc(c,f)
547	#define putchar(c)	fputc(c,stdout)
548
549	#if _BLD_ast && defined(__EXPORT__)
550	#define extern		__EXPORT__
551	#endif
552
553	extern int		_sffilbuf(FILE*, int);
554	extern int		_sfflsbuf(FILE*, int);
555
556	#undef	extern
557
558	#endif
559}end
560