1set	prototyped
2iff	AST_SYS
3ref	-D_def_map_ast
4
5print	#if __mips == 2 && !defined(_NO_LARGEFILE64_SOURCE)
6print	#define	_NO_LARGEFILE64_SOURCE	1
7print	#endif
8print	#if !defined(_NO_LARGEFILE64_SOURCE) && _typ_off64_t && _lib_lseek64 && _lib_stat64
9print	#if !defined(_LARGEFILE64_SOURCE)
10print	#define _LARGEFILE64_SOURCE	1
11print	#endif
12print	#if !defined(_LARGEFILE_SOURCE)
13print	#define _LARGEFILE_SOURCE	1
14print	#endif
15print	#if !defined(_LARGE_FILE_API)
16print	#define _LARGE_FILE_API		1
17print	#endif
18print	#else
19print	#undef	_LARGEFILE64_SOURCE
20print	#undef	_LARGEFILE_SOURCE
21print	#undef	_LARGE_FILE_API
22print	#undef	_typ_ino64_t
23print	#undef	_typ_off64_t
24print	#undef	_typ_struct_dirent64
25print	#undef	_lib_creat64
26print	#undef	_lib_fstat64
27print	#undef	_lib_fstatvfs64
28print	#undef	_lib_ftruncate64
29print	#undef	_lib_lseek64
30print	#undef	_lib_lstat64
31print	#undef	_lib_mmap64
32print	#undef	_lib_open64
33print	#undef	_lib_readdir64
34print	#undef	_lib_stat64
35print	#undef	_lib_statvfs64
36print	#undef	_lib_truncate64
37print	#endif
38print	#if !_lib_readdir64
39print	#undef	_typ_ino64_t
40print	#endif
41
42print	#if defined(__STDC__) && !defined(__USE_FIXED_PROTOTYPES__)
43print	#define __USE_FIXED_PROTOTYPES__	1	/* kick gcc out of the past */
44print	#endif
45
46header	stdlib.h
47header	stddef.h
48header	sys/types.h
49header	stdint.h
50header	inttypes.h
51header	string.h
52header	unistd.h
53header	limits.h
54header	fcntl.h
55header	locale.h
56
57typ dev_t,nlink_t fail{
58	echo "#ifndef $m"
59	echo "#define $m	1"
60	echo "typedef short $v;"
61	echo "#endif"
62}end
63typ gid_t,mode_t,uid_t fail{
64	echo "#ifndef $m"
65	echo "#define $m	1"
66	echo "typedef unsigned short $v;"
67	echo "#endif"
68}end
69typ wchar_t stdio.h wchar.h fail{
70	echo "#ifndef $m"
71	echo "#define $m	1"
72	echo "typedef unsigned short $v;"
73	echo "#endif"
74}end
75typ pid_t,ssize_t fail{
76	echo "#ifndef $m"
77	echo "#define $m	1"
78	echo "typedef int $v;"
79	echo "#endif"
80}end
81typ wint_t stdio.h wchar.h fail{
82	echo "#ifndef $m"
83	echo "#define $m	1"
84	echo "typedef int $v;"
85	echo "#endif"
86}end
87typ socklen_t sys/socket.h fail{
88	echo "#ifndef $m"
89	echo "#define $m	1"
90	echo "typedef int $v;"
91	echo "#endif"
92}end
93typ size_t fail{
94	echo "#ifndef $m"
95	echo "#define $m	1"
96	echo "typedef unsigned int $v;"
97	echo "#endif"
98}end
99typ clock_t,ino_t,off_t,ptrdiff_t fail{
100	echo "#ifndef $m"
101	echo "#define $m	1"
102	echo "typedef long $v;"
103	echo "#endif"
104}end
105typ time_t fail{
106	echo "#ifndef $m"
107	echo "#define $m	1"
108	echo "typedef unsigned long $v;"
109	echo "#endif"
110}end
111typ div_t fail{
112	echo "#ifndef $m"
113	echo "#define $m	1"
114	echo "typedef struct { int quot; int rem; } $v;"
115	echo "#endif"
116}end
117typ ldiv_t fail{
118	echo "#ifndef $m"
119	echo "#define $m	1"
120	echo "typedef struct { long quot; long rem; } $v;"
121	echo "#endif"
122}end
123tst	typ_signed_size_t output{
124	#include <sys/types.h>
125	int
126	main()
127	{
128		unsigned long u = ~0;
129		size_t s = ~0;
130		if (s >= 0)
131			return 1;
132		printf("#if !defined(__cplusplus) && !defined(c_plusplus) && !defined(_typ_signed_size_t)\n/* what dipsticks made size_t signed? sun. */\ntypedef unsigned %s _ast_size_t;\n#undef\tsize_t\n#define size_t\t_ast_size_t\n#endif\n", u == (unsigned long)s ? "long" : "int");
133		return 0;
134	}
135}end
136
137define	offsetof	(type,member)	((size_t)&(((type*)0)->member))
138define	EXIT_FAILURE	1
139define	EXIT_SUCCESS	0
140define	MB_CUR_MAX	1
141define	RAND_MAX	32767
142
143define	STDIN_FILENO	0
144define	STDOUT_FILENO	1
145define	STDERR_FILENO	2
146
147define	NULL		0
148
149define	SEEK_SET	0
150define	SEEK_CUR	1
151define	SEEK_END	2
152
153define	F_OK		0
154define	X_OK		1
155define	W_OK		2
156define	R_OK		4
157
158print	#if _BLD_ast && defined(__EXPORT__)
159print	#define extern	__EXPORT__
160print	#endif
161
162extern	_exit		void		(int)
163extern	abort		void		(void)
164extern	abs		int		(int)
165extern	access		int		(const char*, int)
166extern	alarm		unsigned	(unsigned)
167extern	atexit		int		(void(*)(void))
168extern	atof		double		(const char*)
169extern	atoi		int		(const char*)
170extern	atol		long		(const char*)
171extern	bsearch		void*		(const void*, const void*, size_t, size_t, int(*)(const void*, const void*))
172extern	calloc		void*		(size_t, size_t)
173extern	cfree		void		(void*)
174extern	chdir		int		(const char*)
175extern	chown		int		(const char*, uid_t, gid_t)
176extern	close		int		(int)
177extern	confstr		size_t		(int, char*, size_t)
178extern	div		div_t		(int, int)
179extern	dup		int		(int)
180extern	dup2		int		(int, int)
181extern	eaccess		int		(const char*, int)
182extern	execl		int		(const char*, const char*, ...)
183extern	execle		int		(const char*, const char*, ...)
184extern	execlp		int		(const char*, const char*, ...)
185extern	execv		int		(const char*, char* const[])
186extern	execve		int		(const char*, char* const[], char* const[])
187extern	execve		int		(const char*, char* const[], char* const[])
188extern	execvp		int		(const char*, char* const[])
189extern	execvpe		int		(const char*, char* const[], char* const[])
190extern	exit		void		(int)
191extern	fork		pid_t		(void)
192extern	fpathconf	long		(int, int)
193extern	free		void		(void*)
194extern	fsync		int		(int)
195extern	ftruncate	int		(int, off_t)
196extern	getcwd		char*		(char*, size_t)
197extern	getegid		gid_t		(void)
198extern	getenv		char*		(const char*)
199extern	geteuid		uid_t		(void)
200extern	getgid		gid_t		(void)
201extern	getgroups	int		(int, gid_t[])
202extern	getlogin	char*		(void)
203extern	getpgrp		pid_t		(void)
204extern	getpid		pid_t		(void)
205extern	getppid		pid_t		(void)
206extern	gettxt		char*		(const char*, const char*)
207extern	getuid		uid_t		(void)
208extern	isatty		int		(int)
209extern	labs		long		(long)
210extern	ldiv		ldiv_t		(long, long)
211extern	link		int		(const char*, const char*)
212extern	lseek		off_t		(int, off_t, int)
213extern	malloc		void*		(size_t)
214extern	mblen		int		(const char*, size_t)
215extern	mbstowcs	size_t		(wchar_t*, const char*, size_t)
216extern	mbtowc		int		(wchar_t*, const char*, size_t)
217extern	memalign	void*		(size_t, size_t)
218extern	memccpy		void*		(void*, const void*, int, size_t)
219extern	memchr		void*		(const void*, int, size_t)
220extern	memcmp		int		(const void*, const void*, size_t)
221extern	memcpy		void*		(void*, const void*, size_t)
222extern	memmove		void*		(void*, const void*, size_t)
223extern	memset		void*		(void*, int, size_t)
224extern	pathconf	long		(const char*, int)
225extern	pause		int		(void)
226extern	pipe		int		(int[])
227extern	pvalloc		void*		(size_t)
228extern	qsort		void		(void*, size_t, size_t, int(*)(const void*, const void*))
229extern	rand		int		(void)
230extern	read		ssize_t		(int, void*, size_t)
231extern	realloc		void*		(void*, size_t)
232extern	realpath	char*		(const char*, char*)
233extern	resolvepath	char*		(const char*, char*, size_t)
234extern	rmdir		int		(const char*)
235extern	setgid		int		(gid_t)
236extern	setpgid		int		(pid_t, pid_t)
237extern	setsid		pid_t		(void)
238extern	setuid		int		(uid_t)
239extern	sleep		unsigned		(unsigned int)
240extern	spawnveg	pid_t		(const char*, char* const[], char* const[], pid_t)
241extern	srand		void		(unsigned int)
242extern	strcasecmp	int		(const char*, const char*)
243extern	strcat		char*		(char*, const char*)
244extern	strchr		char*		(const char*, int)
245extern	strcmp		int		(const char*, const char*)
246extern	strcoll		int		(const char*, const char*)
247extern	strcpy		char*		(char*, const char*)
248extern	strcspn		size_t		(const char*, const char*)
249extern	strdup		char*		(const char*)
250extern	strlcat		size_t		(char*, const char*, size_t)
251extern	strlcpy		size_t		(char*, const char*, size_t)
252extern	strlen		size_t		(const char*)
253extern	strncasecmp	int		(const char*, const char*, size_t)
254extern	strncat		char*		(char*, const char*, size_t)
255extern	strncmp		int		(const char*, const char*, size_t)
256extern	strncpy		char*		(char*, const char*, size_t)
257extern	strpbrk		char*		(const char*, const char*)
258extern	strrchr		char*		(const char*, int)
259extern	strspn		size_t		(const char*, const char*)
260extern	strstr		char*		(const char*, const char*)
261extern	strtok		char*		(char*, const char*)
262extern	strxfrm		size_t		(char*, const char*, size_t)
263extern	swab		void		(const void*, void*, ssize_t)
264extern	sysconf		long		(int)
265extern	system		int		(const char*)
266extern	tcgetpgrp	pid_t		(int)
267extern	tcsetpgrp	int		(int, pid_t)
268extern	truncate	int		(const char*, off_t)
269extern	ttyname		char*		(int)
270extern	unlink		int		(const char*)
271extern	valloc		void*		(size_t)
272extern	wcstombs	size_t		(char*, const wchar_t*, size_t)
273extern	wctomb		int		(char*, wchar_t)
274extern	write		ssize_t		(int, const void*, size_t)
275
276print	#undef	extern
277
278# <stdarg.h> is handled by proto so this must be after the last test
279
280print	#include <stdarg.h>
281