xref: /titanic_50/usr/src/lib/libast/common/features/stdio (revision 5ccb772abc560e890444ecf1d8258ab113840ad7)
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 size_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 size_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	extern void	flockfile(FILE*);
188	extern int	ftrylockfile(FILE*);
189	extern void	funlockfile(FILE*);
190
191	#ifdef _USE_GNU
192
193	extern int	fcloseall(void);
194	extern FILE*	fmemopen(void*, size_t, const char*);
195	extern ssize_t	__getdelim(char**, size_t*, int, FILE*);
196	extern ssize_t	getdelim(char**, size_t*, int, FILE*);
197	extern ssize_t	getline(char**, size_t*, FILE*);
198
199	#endif
200
201	#endif
202}end
203output{
204	#include <stdio.h>
205	#ifndef FILENAME_MAX
206	#ifndef NAME_MAX
207	#ifndef _POSIX_NAME_MAX
208	#define _POSIX_NAME_MAX	14
209	#endif
210	#define NAME_MAX	_POSIX_NAME_MAX
211	#endif
212	#define FILENAME_MAX	NAME_MAX
213	#endif
214	#ifndef FOPEN_MAX
215	#ifdef STREAM_MAX
216	#define FOPEN_MAX	STREAM_MAX
217	#else
218	#ifndef OPEN_MAX
219	#ifndef _POSIX_OPEN_MAX
220	#define _POSIX_OPEN_MAX	20
221	#endif
222	#define OPEN_MAX	_POSIX_OPEN_MAX
223	#endif
224	#define FOPEN_MAX	OPEN_MAX
225	#endif
226	#endif
227	#ifndef TMP_MAX
228	#define TMP_MAX		33520641
229	#endif
230	int
231	main()
232	{
233		printf("#ifndef FILENAME_MAX\n");
234		printf("#define FILENAME_MAX	%d\n", FILENAME_MAX);
235		printf("#endif\n");
236		printf("#ifndef FOPEN_MAX\n");
237		printf("#define FOPEN_MAX	%d\n", FOPEN_MAX);
238		printf("#endif\n");
239		printf("#ifndef TMP_MAX\n");
240		printf("#define TMP_MAX		%d\n", TMP_MAX);
241		printf("#endif\n");
242	#if !_UWIN
243		printf("\n");
244		printf("#define _doprnt		_ast_doprnt\n");
245		printf("#define _doscan		_ast_doscan\n");
246		printf("#define asprintf	_ast_asprintf\n");
247		printf("#define clearerr	_ast_clearerr\n");
248		printf("#define fclose		_ast_fclose\n");
249		printf("#define fdopen		_ast_fdopen\n");
250		printf("#define fflush		_ast_fflush\n");
251		printf("#define fgetc		_ast_fgetc\n");
252		printf("#define fgetpos		_ast_fgetpos\n");
253		printf("#define fgetpos64	_ast_fgetpos64\n");
254		printf("#define fgets		_ast_fgets\n");
255		printf("#define fopen		_ast_fopen\n");
256		printf("#define fprintf		_ast_fprintf\n");
257		printf("#define fpurge		_ast_fpurge\n");
258		printf("#define fputs		_ast_fputs\n");
259		printf("#define fread		_ast_fread\n");
260		printf("#define freopen		_ast_freopen\n");
261		printf("#define fscanf		_ast_fscanf\n");
262		printf("#define fseek		_ast_fseek\n");
263		printf("#define fseek64		_ast_fseek64\n");
264		printf("#define fseeko		_ast_fseeko\n");
265		printf("#define fseeko64	_ast_fseeko64\n");
266		printf("#define fsetpos		_ast_fsetpos\n");
267		printf("#define fsetpos64	_ast_fsetpos64\n");
268		printf("#define ftell		_ast_ftell\n");
269		printf("#define ftell64		_ast_ftell64\n");
270		printf("#define ftello		_ast_ftello\n");
271		printf("#define ftello64	_ast_ftello64\n");
272		printf("#define fwrite		_ast_fwrite\n");
273		printf("#define gets		_ast_gets\n");
274		printf("#define getw		_ast_getw\n");
275		printf("#define pclose		_ast_pclose\n");
276		printf("#define popen		_ast_popen\n");
277		printf("#define printf		_ast_printf\n");
278		printf("#define puts		_ast_puts\n");
279		printf("#define putw		_ast_putw\n");
280		printf("#define rewind		_ast_rewind\n");
281		printf("#define scanf		_ast_scanf\n");
282		printf("#define setbuf		_ast_setbuf\n");
283		printf("#undef	setbuffer\n");
284		printf("#define setbuffer	_ast_setbuffer\n");
285		printf("#define setlinebuf	_ast_setlinebuf\n");
286		printf("#define setvbuf		_ast_setvbuf\n");
287		printf("#define snprintf	_ast_snprintf\n");
288		printf("#define sprintf		_ast_sprintf\n");
289		printf("#define sscanf		_ast_sscanf\n");
290		printf("#define tmpfile		_ast_tmpfile\n");
291		printf("#define ungetc		_ast_ungetc\n");
292		printf("#define vasprintf	_ast_vasprintf\n");
293		printf("#define vfprintf	_ast_vfprintf\n");
294		printf("#define vfscanf		_ast_vfscanf\n");
295		printf("#define vprintf		_ast_vprintf\n");
296		printf("#define vscanf		_ast_vscanf\n");
297		printf("#define vsnprintf	_ast_vsnprintf\n");
298		printf("#define vsprintf	_ast_vsprintf\n");
299		printf("#define vsscanf		_ast_vsscanf\n");
300
301		printf("#define fcloseall	_ast_fcloseall\n");
302		printf("#define _filbuf		_ast__filbuf\n");
303		printf("#define fmemopen	_ast_fmemopen\n");
304		printf("#define __getdelim	_ast___getdelim\n");
305		printf("#define getdelim	_ast_getdelim\n");
306		printf("#define getline		_ast_getline\n");
307
308		printf("#define clearerr_unlocked _ast_clearerr_unlocked\n");
309		printf("#define feof_unlocked	_ast_feof_unlocked\n");
310		printf("#define ferror_unlocked	_ast_ferror_unlocked\n");
311		printf("#define fflush_unlocked	_ast_fflush_unlocked\n");
312		printf("#define fgetc_unlocked	_ast_fgetc_unlocked\n");
313		printf("#define fgets_unlocked	_ast_fgets_unlocked\n");
314		printf("#define fileno_unlocked	_ast_fileno_unlocked\n");
315		printf("#define fputc_unlocked	_ast_fputc_unlocked\n");
316		printf("#define fputs_unlocked	_ast_fputs_unlocked\n");
317		printf("#define fread_unlocked	_ast_fread_unlocked\n");
318		printf("#define fwrite_unlocked	_ast_fwrite_unlocked\n");
319		printf("#define getc_unlocked	_ast_getc_unlocked\n");
320		printf("#define getchar_unlocked _ast_getchar_unlocked\n");
321		printf("#define putc_unlocked	_ast_putc_unlocked\n");
322		printf("#define putchar_unlocked _ast_putchar_unlocked\n");
323
324		printf("#define flockfile	_ast_flockfile\n");
325		printf("#define ftrylockfile	_ast_ftrylockfile\n");
326		printf("#define funlockfile	_ast_funlockfile\n");
327
328		printf("\n");
329	#endif
330		return 0;
331	}
332}end
333macro{
334	<<"#if defined(__STDPP__directive) && defined(__STDPP__initial)">>
335	<<"__STDPP__directive pragma pp:initial">>
336	<<"#endif">>
337	<<"#ifndef P_tmpdir">>
338	#ifndef P_tmpdir
339	#define P_tmpdir "/usr/tmp/"
340	#endif
341	<<"#define P_tmpdir">> P_tmpdir <<"/*NOCATLITERAL*/">>
342	<<"#endif">>
343	<<"#ifndef L_ctermid">>
344	#ifndef L_ctermid
345	#define L_ctermid 9
346	#endif
347	<<"#define L_ctermid">> L_ctermid
348	<<"#endif">>
349	<<"#ifndef L_tmpnam">>
350	#ifndef L_tmpnam
351	#define L_tmpnam (sizeof(P_tmpdir)+15)
352	#endif
353	<<"#define L_tmpnam">> L_tmpnam
354	<<"#endif">>
355	<<"#if defined(__STDPP__directive) && defined(__STDPP__initial)">>
356	<<"__STDPP__directive pragma pp:noinitial">>
357	<<"#endif">>
358}end
359cat{
360	#if defined(__cplusplus) && defined(__THROW)
361	extern char*	ctermid(char*) __THROW;
362	#else
363	extern char*	ctermid(char*);
364	#endif
365	extern char*	tmpnam(char*);
366	extern char*	tempnam(const char*, const char*);
367	extern void	perror(const char*);
368	#ifndef _AST_STD_H
369	#ifndef remove
370	extern int	remove(const char*);
371	#endif
372	#ifndef rename
373	extern int	rename(const char*, const char*);
374	#endif
375	#endif
376
377	#undef	extern
378
379	#if _BLD_ast && defined(__EXPORT__)
380	#define extern		__EXPORT__
381	#endif
382
383	extern int	_doprnt(const char*, va_list, FILE*);
384	extern int	_doscan(FILE*, const char*, va_list);
385	extern int	asprintf(char**, const char*, ...);
386	extern int	clearerr(FILE*);
387	extern int	fclose(FILE*);
388	extern FILE*	fdopen(int, const char*);
389	extern int	feof(FILE*);
390	extern int	ferror(FILE*);
391	extern int	fflush(FILE*);
392	extern int	fgetc(FILE*);
393	extern int	fgetpos(FILE*, fpos_t*);
394	extern char*	fgets(char*, int, FILE*);
395	extern int	fileno(FILE*);
396	extern FILE*	fopen(const char*, const char*);
397	extern int	fprintf(FILE*, const char*, ...);
398	extern int	fpurge(FILE*);
399	extern int	fputc(int, FILE*);
400	extern int	fputs(const char*, FILE*);
401	extern size_t	fread(void*, size_t, size_t, FILE*);
402	extern FILE*	freopen(const char*, const char*, FILE*);
403	extern int	fscanf(FILE*, const char*, ...);
404	extern int	fseek(FILE*, long, int);
405	extern int	fseeko(FILE*, off_t, int);
406	extern int	fsetpos(FILE*, const fpos_t*);
407	extern long	ftell(FILE*);
408	extern off_t	ftello(FILE*);
409	extern size_t	fwrite(const void*, size_t, size_t, FILE*);
410	extern int	getc(FILE*);
411	extern int	getchar(void);
412	extern char*	gets(char*);
413	extern int	getw(FILE*);
414	extern int	pclose(FILE*);
415	extern FILE*	popen(const char*, const char*);
416	extern int	printf(const char*, ...);
417	extern int	putc(int, FILE*);
418	extern int	putchar(int);
419	extern int	puts(const char*);
420	extern int	putw(int, FILE*);
421	extern void	rewind(FILE*);
422	extern int	scanf(const char*, ...);
423	extern void	setbuf(FILE*, char*);
424	extern int	setbuffer(FILE*, char*, int);
425	extern int	setlinebuf(FILE*);
426	extern int	setvbuf(FILE*, char*, int, size_t);
427	extern int	snprintf(char*, int, const char*, ...);
428	extern int	sprintf(char*, const char*, ...);
429	extern int	sscanf(const char*, const char*, ...);
430	extern FILE*	tmpfile(void);
431	extern int	ungetc(int, FILE*);
432	extern int	vasprintf(char**, const char*, va_list);
433	extern int	vfprintf(FILE*, const char*, va_list);
434	extern int	vfscanf(FILE*, const char*, va_list);
435	extern int	vprintf(const char*, va_list);
436	extern int	vscanf(const char*, va_list);
437	extern int	vsnprintf(char*, int, const char*, va_list);
438	extern int	vsprintf(char*, const char*, va_list);
439	extern int	vsscanf(const char*, const char*, va_list);
440
441	#if _typ_int64_t
442
443	extern int		fgetpos64(FILE*, fpos64_t*);
444	extern int		fsetpos64(FILE*, const fpos64_t*);
445	extern int		fseek64(FILE*, int64_t, int);
446	extern int		fseeko64(FILE*, int64_t, int);
447	extern int64_t		ftell64(FILE*);
448	extern int64_t		ftello64(FILE*);
449
450	#ifdef _LARGEFILE64_SOURCE
451
452	#undef	fpos_t
453	#undef	off_t
454	#undef	fgetpos
455	#undef	fsetpos
456	#undef	fseek
457	#undef	fseeko
458	#undef	ftell
459	#undef	ftello
460
461	#define	fpos_t		fpos64_t
462	#if _typ_off64_t
463	#define	off_t		off64_t
464	#else
465	#define	off_t		int64_t
466	#endif
467
468	#define fgetpos		fgetpos64
469	#define fsetpos		fsetpos64
470	#define	fseek		fseek64
471	#define	fseeko		fseeko64
472	#define ftell		ftell64
473	#define ftello		ftello64
474
475	#endif
476
477	#endif
478
479	extern void	clearerr_unlocked(FILE*);
480	extern int	feof_unlocked(FILE*);
481	extern int	ferror_unlocked(FILE*);
482	extern int	fflush_unlocked(FILE*);
483	extern int	fgetc_unlocked(FILE*);
484	extern char*	fgets_unlocked(char*, int, FILE*);
485	extern int	fileno_unlocked(FILE*);
486	extern int	fputc_unlocked(int, FILE*);
487	extern int	fputs_unlocked(char*, FILE*);
488	extern size_t	fread_unlocked(void*, size_t, size_t, FILE*);
489	extern size_t	fwrite_unlocked(void*, size_t, size_t, FILE*);
490	extern int	getc_unlocked(FILE*);
491	extern int	getchar_unlocked(void);
492	extern int	putc_unlocked(int, FILE*);
493	extern int	putchar_unlocked(int);
494
495	#ifdef _USE_GNU
496
497	extern int	fcloseall(void);
498	extern FILE*	fmemopen(void*, size_t, const char*);
499	extern ssize_t	__getdelim(char**, size_t*, int, FILE*);
500	extern ssize_t	getdelim(char**, size_t*, int, FILE*);
501	extern ssize_t	getline(char**, size_t*, FILE*);
502
503	#endif
504
505	#undef	extern
506
507	#if _BLD_DLL && _DLL_INDIRECT_DATA
508
509	#define stdin		((FILE*)_ast_dll->_ast_stdin)
510	#define stdout		((FILE*)_ast_dll->_ast_stdout)
511	#define stderr		((FILE*)_ast_dll->_ast_stderr)
512
513	#else
514
515	#define	stdin		(&_Sfstdin)
516	#define	stdout		(&_Sfstdout)
517	#define	stderr		(&_Sfstderr)
518
519	#endif
520
521	#if defined(_AST_H) || defined(_SFIO_H)
522
523	#define feof(f)		sfeof(f)
524	#define ferror(f)	sferror(f)
525	#define fileno(f)	sffileno(f)
526	#define fputc(c,f)	sfputc(f,c)
527	#define getc(f)		sfgetc(f)
528	#define getchar()	sfgetc(sfstdin)
529	#define putc(c,f)	sfputc(f,c)
530	#define putchar(c)	sfputc(sfstdout,c)
531
532	#else
533
534	#if !_UWIN
535	#if _BLD_ast && defined(__EXPORT__)
536	#define extern		extern __EXPORT__
537	#endif
538	#if !_BLD_ast && defined(__IMPORT__)
539	#define extern		extern __IMPORT__
540	#endif
541	#endif
542
543	extern FILE	_Sfstdin;
544	extern FILE	_Sfstdout;
545	extern FILE	_Sfstderr;
546
547	#undef	extern
548
549	#define feof(f)		(_sf_(f)->_flags&_SF_EOF)
550	#define ferror(f)	(_sf_(f)->_flags&_SF_ERROR)
551	#define fileno(f)	(_sf_(f)->_file)
552	#define fputc(c,f)	(_sf_(f)->_next>=_sf_(f)->_endw?_sfflsbuf(_sf_(f),(int)((unsigned char)(c))):(int)(*_sf_(f)->_next++=(unsigned char)(c)))
553	#define getc(f)		(_sf_(f)->_next>=_sf_(f)->_endr?_sffilbuf(_sf_(f),0):(int)(*_sf_(f)->_next++))
554	#define getchar()	getc(stdin)
555	#define putc(c,f)	fputc(c,f)
556	#define putchar(c)	fputc(c,stdout)
557
558	#if _BLD_ast && defined(__EXPORT__)
559	#define extern		__EXPORT__
560	#endif
561
562	extern int		_sffilbuf(FILE*, int);
563	extern int		_sfflsbuf(FILE*, int);
564
565	#undef	extern
566
567	#endif
568}end
569