1da2e3ebdSchinref	-D_def_map_ast=1
2da2e3ebdSchin
3da2e3ebdSchincmd	universe
4da2e3ebdSchin
5da2e3ebdSchinhdr	dirent,direntry,filio,fmtmsg,fnmatch,jioctl,libgen,limits
6*b30d1939SAndy Fiddamanhdr	locale,ndir,nl_types,process,spawn,syslog,utime,vfork
7da2e3ebdSchinhdr	wchar note{ <wchar.h> and isw*() really work }end execute{
8da2e3ebdSchin	#include <wchar.h>
9da2e3ebdSchin	int
10da2e3ebdSchin	main()
11da2e3ebdSchin	{
12da2e3ebdSchin		wchar_t	w = 'a';
13da2e3ebdSchin		return iswalnum(w) == 0;
14da2e3ebdSchin	}
15da2e3ebdSchin}end
16*b30d1939SAndy Fiddamanhdr	wctype wchar.h
17da2e3ebdSchin
18da2e3ebdSchindat	_tzname,tzname
19da2e3ebdSchin
20da2e3ebdSchinlib	BSDsetpgrp
21da2e3ebdSchinlib	_cleanup
22da2e3ebdSchinlib	atexit,bcopy,bzero,catclose,catgets,catopen,confstr,dirread,dup2
23da2e3ebdSchinlib	execlp,execve,execvp,execvpe
24da2e3ebdSchinlib	fchmod,fcntl,fmtmsg,fnmatch,fork,fsync
25da2e3ebdSchinlib	getconf,getdents,getdirentries,getdtablesize,getdate
26da2e3ebdSchinlib	getgroups,gethostname,getlogin,getpagesize,getrlimit,getuniverse
27da2e3ebdSchinlib	getopt,getsubopt,getopt_long,getopt_long_only
28da2e3ebdSchinlib	glob,index,iswblank,iswctype,killpg,link,localeconv,madvise
29da2e3ebdSchinlib	mbtowc,mbrtowc,memalign,memchr,memcpy,memdup,memmove,memset
30da2e3ebdSchinlib	mkdir,mkfifo,mktemp,mktime
31da2e3ebdSchinlib	mount,on_exit,onexit,opendir,pathconf
32da2e3ebdSchinlib	readlink,remove,rename,rewinddir,rindex,rmdir,setlocale
33da2e3ebdSchinlib	setpgid,setpgrp,setpgrp2,setreuid,setsid,setuid,sigaction
34da2e3ebdSchinlib	sigprocmask,sigsetmask,sigunblock,sigvec,socketpair
35da2e3ebdSchinlib	spawn,spawnve,spawnveg
36da2e3ebdSchinlib	strchr,strcoll,strdup,strerror,strcasecmp,strncasecmp,strrchr,strstr
37da2e3ebdSchinlib	strmode,strxfrm,strftime,swab,symlink,sysconf,sysinfo,syslog
38da2e3ebdSchinlib	telldir,tmpnam,tzset,universe,unlink,utime,wctype
39da2e3ebdSchinlib	ftruncate,truncate
40da2e3ebdSchinlib	creat64,fstat64,fstatvfs64,ftruncate64 -D_LARGEFILE64_SOURCE
41da2e3ebdSchinlib	lseek64,lstat64 -D_LARGEFILE64_SOURCE
42da2e3ebdSchinlib	open64,readdir64,stat64,statvfs64,truncate64 -D_LARGEFILE64_SOURCE
43da2e3ebdSchin
44da2e3ebdSchinlib,npt	strtod,strtold,strtol,strtoll,strtoul,strtoull stdlib.h
453e14f97fSRoger A. Faulknerlib,npt	sigflag signal.h
46da2e3ebdSchin
47da2e3ebdSchinmem	direct.d_reclen sys/types.h sys/dir.h
48da2e3ebdSchinmem	dirent.d_fileno,dirent.d_ino,dirent.d_namlen,dirent.d_off,dirent.d_reclen,dirent.d_type sys/types.h dirent.h
49da2e3ebdSchinmem	DIR sys/types.h - dirent.h - sys/dir.h
50da2e3ebdSchinmem	DIR.dd_fd sys/types.h - dirent.h - sys/dir.h
51da2e3ebdSchinmem	inheritance.pgroup spawn.h
52da2e3ebdSchin
53da2e3ebdSchinsys	dir,filio,jioctl,localedef,ptem,resource
54da2e3ebdSchinsys	socket,stream,systeminfo,universe,vfork
55da2e3ebdSchin
56*b30d1939SAndy Fiddamantyp	ino64_t,off64_t -D_LARGEFILE64_SOURCE
57da2e3ebdSchintyp	struct.dirent64 -D_LARGEFILE64_SOURCE dirent.h
58da2e3ebdSchin
59da2e3ebdSchintst	tst_errno note{ errno can be assigned }end link{
60da2e3ebdSchin	_BEGIN_EXTERNS_
61da2e3ebdSchin	#define error		______error
62da2e3ebdSchin	#define strerror	______strerror
63da2e3ebdSchin	#include <errno.h>
64da2e3ebdSchin	#undef	error
65da2e3ebdSchin	#undef	strerror
66da2e3ebdSchin	#ifndef errno
67da2e3ebdSchin	extern int errno;
68da2e3ebdSchin	#endif
69da2e3ebdSchin	error() { }
70da2e3ebdSchin	strerror() { }
71da2e3ebdSchin	_END_EXTERNS_
72da2e3ebdSchin	int main() { errno = 0; error(); strerror(); return 0; }
73da2e3ebdSchin}end
74da2e3ebdSchin
75da2e3ebdSchintst	lib_poll_fd_1 note{ fd is first arg to poll() }end execute{
76da2e3ebdSchin	#include <poll.h>
77da2e3ebdSchin	_BEGIN_EXTERNS_
78da2e3ebdSchin	extern int	pipe _ARG_((int*));
79da2e3ebdSchin	_END_EXTERNS_
80da2e3ebdSchin	int
81da2e3ebdSchin	main()
82da2e3ebdSchin	{	int		rw[2];
83da2e3ebdSchin		struct pollfd	fd;
84da2e3ebdSchin		if (pipe(rw) < 0) return 1;
85da2e3ebdSchin		fd.fd = rw[0];
86da2e3ebdSchin		fd.events = POLLIN;
87da2e3ebdSchin		fd.revents = 0;
88da2e3ebdSchin		if (poll(&fd, 1, 0) < 0 || fd.revents != 0) return 1;
89da2e3ebdSchin		if (write(rw[1], "x", 1) != 1) return 1;
90da2e3ebdSchin		if (poll(&fd, 1, 0) < 0 || fd.revents == 0) return 1;
91da2e3ebdSchin		return 0;
92da2e3ebdSchin	}
93da2e3ebdSchin}end
94da2e3ebdSchin
95da2e3ebdSchintst	lib_poll_fd_2 note{ fd is second arg to poll() }end execute{
96da2e3ebdSchin	#include <poll.h>
97da2e3ebdSchin	_BEGIN_EXTERNS_
98da2e3ebdSchin	extern int	pipe _ARG_((int*));
99da2e3ebdSchin	_END_EXTERNS_
100da2e3ebdSchin	int
101da2e3ebdSchin	main()
102da2e3ebdSchin	{	int		rw[2];
103da2e3ebdSchin		struct pollfd	fd;
104da2e3ebdSchin		if (pipe(rw) < 0) return 1;
105da2e3ebdSchin		fd.fd = rw[0];
106da2e3ebdSchin		fd.events = POLLIN;
107da2e3ebdSchin		fd.revents = 0;
108da2e3ebdSchin		return poll(1, &fd, 0) < 0;
109da2e3ebdSchin		if (poll(1, &fd, 0) < 0 || fd.revents != 0) return 1;
110da2e3ebdSchin		if (write(rw[1], "x", 1) != 1) return 1;
111da2e3ebdSchin		if (poll(1, &fd, 0) < 0 || fd.revents == 0) return 1;
112da2e3ebdSchin		return 0;
113da2e3ebdSchin	}
114da2e3ebdSchin}end
115da2e3ebdSchin
116da2e3ebdSchinexp	_lib_poll	_lib_poll_fd_1||_lib_poll_fd_2
117da2e3ebdSchin
118da2e3ebdSchintst	lib_poll_notimer note{ poll with no fds ignores timeout }end execute{
119da2e3ebdSchin	#include <sys/types.h>
120da2e3ebdSchin	#include <poll.h>
121da2e3ebdSchin	_BEGIN_EXTERNS_
122da2e3ebdSchin	extern time_t	time _ARG_((time_t*));
123da2e3ebdSchin	_END_EXTERNS_
124da2e3ebdSchin	#define TIMEOUT		4
125da2e3ebdSchin	int
126da2e3ebdSchin	main()
127da2e3ebdSchin	{
128da2e3ebdSchin		unsigned long	start;
129da2e3ebdSchin		unsigned long	finish;
130da2e3ebdSchin		struct pollfd	fd;
131da2e3ebdSchin		start = time((time_t*)0);
132da2e3ebdSchin		if (poll(&fd, 0, TIMEOUT * 1000) < 0)
133da2e3ebdSchin			return 0;
134da2e3ebdSchin		finish = time((time_t*)0);
135da2e3ebdSchin		return (finish - start) > (TIMEOUT / 2);
136da2e3ebdSchin	}
137da2e3ebdSchin}end
138da2e3ebdSchin
139*b30d1939SAndy Fiddamantst	lib_select sys/select.h note{ select() has standard 5 arg interface }end link{
140da2e3ebdSchin	#include <sys/types.h>
141da2e3ebdSchin	#include <sys/time.h>
142da2e3ebdSchin	#include <sys/socket.h>
143da2e3ebdSchin	int
144da2e3ebdSchin	main()
145da2e3ebdSchin	{	struct timeval	tmb;
146da2e3ebdSchin		fd_set		rd;
147da2e3ebdSchin		FD_ZERO(&rd);
148da2e3ebdSchin		FD_SET(0,&rd);
149da2e3ebdSchin		tmb.tv_sec = 0;
150da2e3ebdSchin		tmb.tv_usec = 0;
151da2e3ebdSchin		select(1,&rd,(fd_set*)0,(fd_set*)0,&tmb);
152da2e3ebdSchin		return 0;
153da2e3ebdSchin	}
154da2e3ebdSchin}end
155da2e3ebdSchin
156*b30d1939SAndy Fiddamantst	sys_select note{ select() requires <sys/select.h> }end link{
157*b30d1939SAndy Fiddaman	#include <sys/select.h>
158*b30d1939SAndy Fiddaman	int
159*b30d1939SAndy Fiddaman	main()
160*b30d1939SAndy Fiddaman	{	struct timeval	tmb;
161*b30d1939SAndy Fiddaman		fd_set		rd;
162*b30d1939SAndy Fiddaman		FD_ZERO(&rd);
163*b30d1939SAndy Fiddaman		FD_SET(0,&rd);
164*b30d1939SAndy Fiddaman		tmb.tv_sec = 0;
165*b30d1939SAndy Fiddaman		tmb.tv_usec = 0;
166*b30d1939SAndy Fiddaman		select(1,&rd,(fd_set*)0,(fd_set*)0,&tmb);
167*b30d1939SAndy Fiddaman		return 0;
168*b30d1939SAndy Fiddaman	}
169*b30d1939SAndy Fiddaman}end
170*b30d1939SAndy Fiddaman
171da2e3ebdSchintst	pipe_rw note{ full duplex pipes }end execute{
172da2e3ebdSchin	_BEGIN_EXTERNS_
173da2e3ebdSchin	extern int	pipe _ARG_((int*));
174da2e3ebdSchin	extern int	read _ARG_((int, void*, int));
175da2e3ebdSchin	extern int	strcmp _ARG_((const char*, const char*));
176da2e3ebdSchin	extern int	write _ARG_((int, void*, int));
177da2e3ebdSchin	_END_EXTERNS_
178da2e3ebdSchin	int
179da2e3ebdSchin	main()
180da2e3ebdSchin	{
181da2e3ebdSchin	#if defined(__sgi) || defined(_sgi) || defined(sgi)
182da2e3ebdSchin		/* boot tuneable pipes force one way for bin compatibility */
183da2e3ebdSchin		return 1;
184da2e3ebdSchin	#else
185da2e3ebdSchin		static char	test[] = "test\n";
186da2e3ebdSchin		int		io[2];
187da2e3ebdSchin		char		buf[sizeof(test)];
188da2e3ebdSchin		if (pipe(io)) return 1;
189da2e3ebdSchin		if (write(io[1], test, sizeof(test)) != sizeof(test)) return 1;
190da2e3ebdSchin		if (read(io[0], buf, sizeof(test)) != sizeof(test)) return 1;
191da2e3ebdSchin		if (strcmp(test, buf)) return 1;
192da2e3ebdSchin		if (write(io[0], test, sizeof(test)) != sizeof(test)) return 1;
193da2e3ebdSchin		if (read(io[1], buf, sizeof(test)) != sizeof(test)) return 1;
194da2e3ebdSchin		if (strcmp(test, buf)) return 1;
195da2e3ebdSchin		return 0;
196da2e3ebdSchin	#endif
197da2e3ebdSchin	}
198da2e3ebdSchin}end
199da2e3ebdSchin
200da2e3ebdSchintst	lib_vfork unistd.h stdlib.h vfork.h note{ vfork exists and it works }end execute{
201da2e3ebdSchin	#include <signal.h>
202da2e3ebdSchin	int
203da2e3ebdSchin	main(argc, argv)
204da2e3ebdSchin	int	argc;
205da2e3ebdSchin	char**	argv;
206da2e3ebdSchin	{
207da2e3ebdSchin		int	status;
208da2e3ebdSchin		char*	cmd[3];
209da2e3ebdSchin		if (argv[1])
210da2e3ebdSchin			_exit(signal(SIGHUP, SIG_DFL) != SIG_IGN);
211da2e3ebdSchin		signal(SIGHUP, SIG_IGN);
212da2e3ebdSchin		switch (vfork())
213da2e3ebdSchin		{
214da2e3ebdSchin		case -1:
215da2e3ebdSchin			_exit(1);
216da2e3ebdSchin		case 0:
217da2e3ebdSchin			cmd[0] = argv[0];
218da2e3ebdSchin			cmd[1] = "test";
219da2e3ebdSchin			cmd[2] = 0;
220da2e3ebdSchin			execv(cmd[0], cmd);
221da2e3ebdSchin			_exit(2);
222da2e3ebdSchin		}
223da2e3ebdSchin		status = 1;
224da2e3ebdSchin		_exit(wait(&status) < 0 || status != 0);
225da2e3ebdSchin 	}
226da2e3ebdSchin}end
227da2e3ebdSchin
228da2e3ebdSchintst	real_vfork note{ vfork child shares data with parent }end execute{
229da2e3ebdSchin	_BEGIN_EXTERNS_
230da2e3ebdSchin	extern int	_exit _ARG_((int));
231da2e3ebdSchin	extern int	vfork _ARG_((void));
232da2e3ebdSchin	_END_EXTERNS_
233da2e3ebdSchin	int		code;
234da2e3ebdSchin	int
235da2e3ebdSchin	main()
236da2e3ebdSchin	{
237da2e3ebdSchin		code = 1;
238da2e3ebdSchin		if (!vfork())
239da2e3ebdSchin			code = 0;
240da2e3ebdSchin		_exit(code);
241da2e3ebdSchin	}
242da2e3ebdSchin}end
243da2e3ebdSchin
244da2e3ebdSchintst	lib_posix_spawn unistd.h stdlib.h spawn.h -Dfork=______fork note{ posix_spawn exists and it works and its worth using }end status{
245da2e3ebdSchin	#include <sys/types.h>
246da2e3ebdSchin	#include <sys/stat.h>
247da2e3ebdSchin	#include <sys/wait.h>
248da2e3ebdSchin	#include <spawn.h>
249da2e3ebdSchin	#include <signal.h>
250da2e3ebdSchin	#include <fcntl.h>
251da2e3ebdSchin	#include <string.h>
252da2e3ebdSchin	/* if it uses fork() why bother? */
253*b30d1939SAndy Fiddaman	#undef fork
254*b30d1939SAndy Fiddaman	pid_t fork _ARG_((void)) { NOTE("uses fork()"); return -1; }
255*b30d1939SAndy Fiddaman	pid_t _fork _ARG_((void)) { NOTE("uses _fork()"); return -1; }
256*b30d1939SAndy Fiddaman	pid_t __fork _ARG_((void)) { NOTE("uses __fork()"); return -1; }
257da2e3ebdSchin	int
258da2e3ebdSchin	main(argc, argv)
259da2e3ebdSchin	int	argc;
260da2e3ebdSchin	char**	argv;
261da2e3ebdSchin	{
262da2e3ebdSchin		char*			s;
263da2e3ebdSchin		pid_t			pid;
264da2e3ebdSchin		posix_spawnattr_t	attr;
265da2e3ebdSchin		int			n;
266da2e3ebdSchin		int			status;
267da2e3ebdSchin		char*			cmd[3];
268da2e3ebdSchin		char			tmp[1024];
269da2e3ebdSchin		if (argv[1])
270da2e3ebdSchin			_exit(signal(SIGHUP, SIG_DFL) != SIG_IGN);
271da2e3ebdSchin		signal(SIGHUP, SIG_IGN);
272da2e3ebdSchin		if (posix_spawnattr_init(&attr))
273*b30d1939SAndy Fiddaman		{
274*b30d1939SAndy Fiddaman			NOTE("posix_spawnattr_init() FAILED");
275da2e3ebdSchin			_exit(0);
276*b30d1939SAndy Fiddaman		}
277da2e3ebdSchin		if (posix_spawnattr_setpgroup(&attr, 0))
278*b30d1939SAndy Fiddaman		{
279*b30d1939SAndy Fiddaman			NOTE("posix_spawnattr_setpgroup() FAILED");
280da2e3ebdSchin			_exit(0);
281*b30d1939SAndy Fiddaman		}
282da2e3ebdSchin		if (posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETPGROUP))
283*b30d1939SAndy Fiddaman		{
284*b30d1939SAndy Fiddaman			NOTE("posix_spawnattr_setflags() FAILED");
285da2e3ebdSchin			_exit(0);
286*b30d1939SAndy Fiddaman		}
287da2e3ebdSchin		/* first try an a.out and verify that SIGHUP is ignored */
288da2e3ebdSchin		cmd[0] = argv[0];
289da2e3ebdSchin		cmd[1] = "test";
290da2e3ebdSchin		cmd[2] = 0;
291da2e3ebdSchin		if (posix_spawn(&pid, cmd[0], 0, &attr, cmd, 0))
292*b30d1939SAndy Fiddaman		{
293*b30d1939SAndy Fiddaman			NOTE("posix_spawn() FAILED");
294da2e3ebdSchin			_exit(0);
295*b30d1939SAndy Fiddaman		}
296da2e3ebdSchin		status = 1;
297*b30d1939SAndy Fiddaman		if (wait(&status) < 0)
298*b30d1939SAndy Fiddaman		{
299*b30d1939SAndy Fiddaman			NOTE("wait() FAILED");
300da2e3ebdSchin			_exit(0);
301*b30d1939SAndy Fiddaman		}
302*b30d1939SAndy Fiddaman		if (status != 0)
303*b30d1939SAndy Fiddaman		{
304*b30d1939SAndy Fiddaman			NOTE("SIGHUP ignored in parent not ignored in child");
305*b30d1939SAndy Fiddaman			_exit(0);
306*b30d1939SAndy Fiddaman		}
307*b30d1939SAndy Fiddaman		/* must return exec-type errors or its useless to us *unless* there is no [v]fork() */
308da2e3ebdSchin		n = strlen(cmd[0]);
309da2e3ebdSchin		if (n >= (sizeof(tmp) - 3))
310*b30d1939SAndy Fiddaman		{
311*b30d1939SAndy Fiddaman			NOTE("test executable path too long");
312da2e3ebdSchin			_exit(0);
313*b30d1939SAndy Fiddaman		}
314da2e3ebdSchin		strcpy(tmp, cmd[0]);
315da2e3ebdSchin		tmp[n] = '.';
316da2e3ebdSchin		tmp[n+1] = 's';
317da2e3ebdSchin		tmp[n+2] = 'h';
318da2e3ebdSchin		tmp[n+3] = 0;
319*b30d1939SAndy Fiddaman		if ((n = open(tmp, O_CREAT|O_WRONLY, S_IRWXU|S_IRWXG|S_IRWXO)) < 0 ||
320*b30d1939SAndy Fiddaman		    chmod(tmp, S_IRWXU|S_IRWXG|S_IRWXO) < 0 ||
321*b30d1939SAndy Fiddaman		    write(n, "exit 99\n", 8) != 8 ||
322*b30d1939SAndy Fiddaman		    close(n) < 0)
323*b30d1939SAndy Fiddaman		{
324*b30d1939SAndy Fiddaman			NOTE("test script create FAILED");
325da2e3ebdSchin			_exit(0);
326*b30d1939SAndy Fiddaman		}
327da2e3ebdSchin		cmd[0] = tmp;
328*b30d1939SAndy Fiddaman		n = 0; /* 0 means reject */
329da2e3ebdSchin		pid = -1;
330da2e3ebdSchin		if (posix_spawn(&pid, cmd[0], 0, &attr, cmd, 0))
331*b30d1939SAndy Fiddaman		{
332da2e3ebdSchin			n = 2;
333*b30d1939SAndy Fiddaman			NOTE("ENOEXEC produces posix_spawn() error (BEST)");
334*b30d1939SAndy Fiddaman		}
335*b30d1939SAndy Fiddaman		else if (pid == -1)
336*b30d1939SAndy Fiddaman			NOTE("ENOEXEC returns pid == -1");
337*b30d1939SAndy Fiddaman		else if (wait(&status) != pid)
338*b30d1939SAndy Fiddaman			NOTE("ENOEXEC produces no child process");
339*b30d1939SAndy Fiddaman		else if (!WIFEXITED(status))
340*b30d1939SAndy Fiddaman			NOTE("ENOEXEC produces signal exit");
341da2e3ebdSchin		else
342da2e3ebdSchin		{
343*b30d1939SAndy Fiddaman			status = WEXITSTATUS(status);
344*b30d1939SAndy Fiddaman			if (status == 127)
345*b30d1939SAndy Fiddaman			{
346*b30d1939SAndy Fiddaman				n = 1;
347*b30d1939SAndy Fiddaman				NOTE("ENOEXEC produces exit status 127 (GOOD)");
348*b30d1939SAndy Fiddaman			}
349*b30d1939SAndy Fiddaman			else if (status == 99)
350*b30d1939SAndy Fiddaman				NOTE("ENOEXEC invokes sh");
351*b30d1939SAndy Fiddaman			else if (status == 0)
352*b30d1939SAndy Fiddaman				NOTE("ENOEXEC reports no error");
353da2e3ebdSchin		}
354da2e3ebdSchin		_exit(n);
355da2e3ebdSchin 	}
356da2e3ebdSchin}end
357da2e3ebdSchin
358da2e3ebdSchintst	lib_spawn_mode unistd.h stdlib.h note{ first spawn arg is mode and it works }end execute{
359da2e3ebdSchin	#include <signal.h>
360da2e3ebdSchin	#include <process.h>
361da2e3ebdSchin	#ifndef P_NOWAIT
362da2e3ebdSchin	#define P_NOWAIT _P_NOWAIT
363da2e3ebdSchin	#endif
364da2e3ebdSchin	int
365da2e3ebdSchin	main(argc, argv)
366da2e3ebdSchin	int	argc;
367da2e3ebdSchin	char**	argv;
368da2e3ebdSchin	{
369da2e3ebdSchin		int	status;
370da2e3ebdSchin		char*	cmd[3];
371da2e3ebdSchin		if (argv[1])
372da2e3ebdSchin			_exit(signal(SIGHUP, SIG_DFL) != SIG_IGN);
373da2e3ebdSchin		signal(SIGHUP, SIG_IGN);
374da2e3ebdSchin		cmd[0] = argv[0];
375da2e3ebdSchin		cmd[1] = "test";
376da2e3ebdSchin		cmd[2] = 0;
377da2e3ebdSchin		if (spawnv(P_NOWAIT, cmd[0], cmd) < 0)
378da2e3ebdSchin			_exit(1);
379da2e3ebdSchin		status = 1;
380da2e3ebdSchin		_exit(wait(&status) < 0 || status != 0);
381da2e3ebdSchin	}
382da2e3ebdSchin}end
383da2e3ebdSchin
384*b30d1939SAndy Fiddamantst	stream_peek note{ ioctl(I_PEEK) works on pipe() }end execute{
385da2e3ebdSchin	#include <sys/types.h>
3863e14f97fSRoger A. Faulkner	#include <unistd.h>
387da2e3ebdSchin	#include <stropts.h>
388da2e3ebdSchin	int
389da2e3ebdSchin	main()
3903e14f97fSRoger A. Faulkner	{	struct strpeek	peek;
3913e14f97fSRoger A. Faulkner		int		fds[2];
3923e14f97fSRoger A. Faulkner		char		ctlbuf[32];
3933e14f97fSRoger A. Faulkner		char		databuf[32];
3943e14f97fSRoger A. Faulkner		peek.flags = 0;
3953e14f97fSRoger A. Faulkner		peek.ctlbuf.maxlen = peek.ctlbuf.len = sizeof(ctlbuf);
3963e14f97fSRoger A. Faulkner		peek.ctlbuf.buf = ctlbuf;
3973e14f97fSRoger A. Faulkner		peek.databuf.maxlen = peek.databuf.len = sizeof(databuf);
3983e14f97fSRoger A. Faulkner		peek.databuf.buf = databuf;
3993e14f97fSRoger A. Faulkner		pipe(fds);
4003e14f97fSRoger A. Faulkner		return ioctl(fds[0],I_PEEK,&peek) < 0;
401da2e3ebdSchin	}
402da2e3ebdSchin}end
403da2e3ebdSchin
404*b30d1939SAndy Fiddamantst	socket_peek note{ recv(MSG_PEEK) works on socketpair() }end execute{
405da2e3ebdSchin	#include <unistd.h>
406da2e3ebdSchin	#include <sys/types.h>
407da2e3ebdSchin	#include <sys/socket.h>
408da2e3ebdSchin	int
409da2e3ebdSchin	main()
410da2e3ebdSchin	{
411da2e3ebdSchin		int		i;
412da2e3ebdSchin		int		fds[2];
413da2e3ebdSchin		char		buf[128];
414da2e3ebdSchin
415da2e3ebdSchin		static char	msg[] = "abcd";
416da2e3ebdSchin
417da2e3ebdSchin		if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds))
418da2e3ebdSchin			return 1;
419da2e3ebdSchin		if (write(fds[1], msg, sizeof(msg)) != sizeof(msg))
420da2e3ebdSchin				return 1;
421da2e3ebdSchin		if (recv(fds[0], buf, sizeof(buf), MSG_PEEK) != sizeof(msg))
422da2e3ebdSchin			return 1;
423da2e3ebdSchin		for (i = 0; i < sizeof(msg); i++)
424da2e3ebdSchin			if (buf[i] != msg[i])
425da2e3ebdSchin				return 1;
426da2e3ebdSchin		if (read(fds[0], buf, sizeof(msg)) != sizeof(msg))
427da2e3ebdSchin			return 1;
428da2e3ebdSchin		for (i = 0; i < sizeof(msg); i++)
429da2e3ebdSchin			if (buf[i] != msg[i])
430da2e3ebdSchin				return 1;
431da2e3ebdSchin		return 0;
432da2e3ebdSchin	}
433da2e3ebdSchin}end
434da2e3ebdSchin
435da2e3ebdSchintst	lib_memcmp string.h note{ standard memcmp interface that works }end execute{
436da2e3ebdSchin	/* sgi again -- we're sick of being their regression test */
437da2e3ebdSchin	#define L	8
438da2e3ebdSchin	char		a[L] = { '0' };
439da2e3ebdSchin	char		b[L] = { '1' };
440da2e3ebdSchin	int
441da2e3ebdSchin	main()
442da2e3ebdSchin	{
443da2e3ebdSchin		return memcmp(a, b, L) >= 0;
444da2e3ebdSchin	}
445da2e3ebdSchin}end
446da2e3ebdSchin
447da2e3ebdSchintst	lib_memccpy string.h unistd.h stdlib.h fcntl.h signal.h sys/types.h sys/stat.h sys/mman.h fcntl.h note{ standard memccpy interface that works }end execute{
448da2e3ebdSchin	#if _STD_
449da2e3ebdSchin	static void gotcha(int sig)
450da2e3ebdSchin	#else
451da2e3ebdSchin	static int gotcha(sig) int sig;
452da2e3ebdSchin	#endif
453da2e3ebdSchin	{
454da2e3ebdSchin		exit(1);
455da2e3ebdSchin	}
456da2e3ebdSchin	#ifdef MAP_PRIVATE
457da2e3ebdSchin	static const char x[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxN";
458da2e3ebdSchin	#if _STD_
459da2e3ebdSchin	static int indict_sgi_ia64_4Q_2004(int n)
460da2e3ebdSchin	#else
461da2e3ebdSchin	static int indict_sgi_ia64_4Q_2004(n) int n;
462da2e3ebdSchin	#endif
463da2e3ebdSchin	{
464da2e3ebdSchin		char*		b;
465da2e3ebdSchin		char*		s;
466da2e3ebdSchin		char*		e;
467da2e3ebdSchin		char*		t;
468da2e3ebdSchin		long		m;
469da2e3ebdSchin		int		d;
470da2e3ebdSchin		char		u[1024];
471da2e3ebdSchin
472da2e3ebdSchin		static char	p[32] = {'/','t','m','p','/','m','m'};
473da2e3ebdSchin
474da2e3ebdSchin		for (d = 7; d < 13; d++)
475da2e3ebdSchin			p[d] = 'X';
476da2e3ebdSchin		p[d] = 0;
477da2e3ebdSchin		if ((d = mkstemp(p)) < 0)
478da2e3ebdSchin			return 1;
479da2e3ebdSchin		remove(p);
480da2e3ebdSchin		for (m = 0; m < n; m++)
481da2e3ebdSchin			if (write(d, x, sizeof(x)-1) != sizeof(x)-1)
482da2e3ebdSchin			{
483da2e3ebdSchin				close(d);
484da2e3ebdSchin				return 1;
485da2e3ebdSchin			}
486da2e3ebdSchin		if (lseek(d, (off_t)0, SEEK_SET))
487da2e3ebdSchin		{
488da2e3ebdSchin			close(d);
489da2e3ebdSchin			return 1;
490da2e3ebdSchin		}
491da2e3ebdSchin		m = n * (sizeof(x)-1);
492da2e3ebdSchin		if (!(b = mmap((void*)0, m, PROT_READ|PROT_WRITE, MAP_PRIVATE, d, (off_t)0)))
493da2e3ebdSchin		{
494da2e3ebdSchin			close(d);
495da2e3ebdSchin			return 1;
496da2e3ebdSchin		}
497da2e3ebdSchin		for (e = (s = b) + m; s < e && (t = memccpy(u, s, 'N', (e-s) > sizeof(u) ? sizeof(u) : (e-s))); s += (t-u))
498da2e3ebdSchin			if ((t-u) != (sizeof(x)-1) || memcmp(u, s, t-u))
499da2e3ebdSchin			{
500da2e3ebdSchin				close(d);
501da2e3ebdSchin				return 1;
502da2e3ebdSchin			}
503da2e3ebdSchin		if (s < e)
504da2e3ebdSchin		{
505da2e3ebdSchin			close(d);
506da2e3ebdSchin			return 1;
507da2e3ebdSchin		}
508da2e3ebdSchin		close(d);
509da2e3ebdSchin		return 0;
510da2e3ebdSchin	}
511da2e3ebdSchin	#endif
512da2e3ebdSchin
513da2e3ebdSchin	int
514da2e3ebdSchin	main ()
515da2e3ebdSchin	{
516da2e3ebdSchin		char	buf[1024];
517da2e3ebdSchin	#ifdef MAP_PRIVATE
518da2e3ebdSchin		char*	srcbuf;
519da2e3ebdSchin		char*	dstbuf;
520da2e3ebdSchin		int	fd;
521da2e3ebdSchin		size_t	siz;
522da2e3ebdSchin		int	i;
523da2e3ebdSchin	#endif
52434f9b3eeSRoland Mainz
52534f9b3eeSRoland Mainz	#if defined(__ia64) || defined(__ia64__) || defined(__itanium__)
52634f9b3eeSRoland Mainz		/*
52734f9b3eeSRoland Mainz		 * 0 faith that the itanium coders will ever get this right
52834f9b3eeSRoland Mainz		 * prove me wrong
52934f9b3eeSRoland Mainz		 */
53034f9b3eeSRoland Mainz
53134f9b3eeSRoland Mainz		return 1;
53234f9b3eeSRoland Mainz	#endif
533da2e3ebdSchin
534da2e3ebdSchin		/*
535da2e3ebdSchin		 * early mac osx failed here -- fixed 3Q 2001
536da2e3ebdSchin		 */
537da2e3ebdSchin
538da2e3ebdSchin		if (memccpy(buf, "abc", 0, sizeof(buf)) != (buf + 4))
539da2e3ebdSchin			return 1;
540da2e3ebdSchin	#ifdef MAP_PRIVATE
541da2e3ebdSchin		siz = 64 * 1024;
542da2e3ebdSchin		if (!(dstbuf = malloc(2 * siz)))
543da2e3ebdSchin			return 0;
544da2e3ebdSchin		if ((fd = open("/dev/zero", O_RDWR)) < 0)
545da2e3ebdSchin			return 0;
546da2e3ebdSchin		if (!(srcbuf = (char*)mmap(NULL, siz, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0)))
547da2e3ebdSchin			return 0;
548da2e3ebdSchin		if (!mmap(srcbuf + siz, siz, PROT_NONE, MAP_PRIVATE, fd, 0))
549da2e3ebdSchin			return 0;
550da2e3ebdSchin		for (i = 0; i < siz; i++)
551da2e3ebdSchin			srcbuf[i] = 'x';
552da2e3ebdSchin		srcbuf[siz - 1] = 0;
553da2e3ebdSchin		alarm(10);
554da2e3ebdSchin		signal(SIGSEGV, gotcha);
555da2e3ebdSchin		signal(SIGBUS, gotcha);
556da2e3ebdSchin		signal(SIGALRM, gotcha);
557da2e3ebdSchin		/*
558da2e3ebdSchin		 * sgi ia64 dumps here as of 3Q 2001
559da2e3ebdSchin		 * bug acknowleged 1Q 2003
560da2e3ebdSchin		 */
561da2e3ebdSchin		memccpy(dstbuf, srcbuf, 0, siz + 10);
562da2e3ebdSchin		alarm(0);
563da2e3ebdSchin		if (strcmp(srcbuf, dstbuf))
564da2e3ebdSchin			return 1;
565da2e3ebdSchin		if (indict_sgi_ia64_4Q_2004(1))
566da2e3ebdSchin			return 1;
567da2e3ebdSchin		if (indict_sgi_ia64_4Q_2004(257))
568da2e3ebdSchin			return 1;
569da2e3ebdSchin	#endif
570da2e3ebdSchin		return 0;
571da2e3ebdSchin	}
572da2e3ebdSchin}end
573da2e3ebdSchin
574da2e3ebdSchintst	lib_utime_now note{ utime works with 0 time vector }end execute{
575da2e3ebdSchin	#include <sys/types.h>
576da2e3ebdSchin	_BEGIN_EXTERNS_
577da2e3ebdSchin	extern int	utime _ARG_((const char*, void*));
578da2e3ebdSchin	_END_EXTERNS_
579da2e3ebdSchin	int
580da2e3ebdSchin	main()
581da2e3ebdSchin	{
582da2e3ebdSchin		return utime(".", (void*)0) == -1;
583da2e3ebdSchin	}
584da2e3ebdSchin}end
585da2e3ebdSchin
586da2e3ebdSchintst	cross{
587da2e3ebdSchin	u=att
588da2e3ebdSchin	case `/bin/cat -s /dev/null/foo 2>&1` in
589da2e3ebdSchin	'')	;;
590da2e3ebdSchin	*)	case `/bin/echo '\\t'` in
591da2e3ebdSchin		'\t')	u=ucb ;;
592da2e3ebdSchin		esac
593da2e3ebdSchin		;;
594da2e3ebdSchin	esac
595da2e3ebdSchin	echo "#define _UNIV_DEFAULT	\"$u\"	/* default universe name */"
596da2e3ebdSchin}end
597da2e3ebdSchin
598da2e3ebdSchinstd	cleanup note{ stuck with standard _cleanup }end noexecute{
599da2e3ebdSchin	_BEGIN_EXTERNS_
600da2e3ebdSchin	extern void exit _ARG_((int));
601da2e3ebdSchin	extern void _exit _ARG_((int));
602da2e3ebdSchin	extern void _cleanup();
603da2e3ebdSchin	void _cleanup() { _exit(0); }
604da2e3ebdSchin	_END_EXTERNS_
605da2e3ebdSchin	int main() { printf("cleanup\n"); exit(1); }
606da2e3ebdSchin}end
607da2e3ebdSchin
608da2e3ebdSchinstd	remove note{ stuck with standard remove() }end nostatic{
609da2e3ebdSchin	_BEGIN_EXTERNS_
610da2e3ebdSchin	extern int unlink _ARG_((const char*));
611da2e3ebdSchin	_END_EXTERNS_
612da2e3ebdSchin	#if _STD_
613da2e3ebdSchin	int remove(const char* path) { return 0; }
614da2e3ebdSchin	#else
615da2e3ebdSchin	int remove(path) char* path; { return 0; }
616da2e3ebdSchin	#endif
617da2e3ebdSchin	int main() { return unlink("foo"); }
618da2e3ebdSchin}end
619da2e3ebdSchin
620da2e3ebdSchinstd	signal note{ stuck with standard signal }end nolink{
621da2e3ebdSchin	_BEGIN_EXTERNS_
622da2e3ebdSchin	extern int abort();
623da2e3ebdSchin	int signal() { return 0; }
624da2e3ebdSchin	_END_EXTERNS_
625da2e3ebdSchin	int main() { signal(); abort(); return 0; }
626da2e3ebdSchin}end
627da2e3ebdSchin
628da2e3ebdSchinstd	strcoll note{ standard strcoll works }end execute{
629da2e3ebdSchin	#include <string.h>
630da2e3ebdSchin	#define S	"hello world"
631da2e3ebdSchin	int
632da2e3ebdSchin	main()
633da2e3ebdSchin	{
634da2e3ebdSchin		char	s[] = S;
635da2e3ebdSchin		char	t[] = S;
636da2e3ebdSchin		return strcoll(s, t) || strcmp(s, t);
637da2e3ebdSchin	}
638da2e3ebdSchin}end
639da2e3ebdSchin
640da2e3ebdSchinstd	strtod stdlib.h note{ stuck with standard strtod }end nostatic{
641da2e3ebdSchin	_BEGIN_EXTERNS_
642da2e3ebdSchin	#if _STD_
643da2e3ebdSchin	double strtod(const char* s, char** e) { return 0.0; }
644da2e3ebdSchin	#else
645da2e3ebdSchin	double strtod(s, e) char* s; char** e; { return 0.0; }
646da2e3ebdSchin	#endif
647da2e3ebdSchin	_END_EXTERNS_
648da2e3ebdSchin	int main() { printf(""); return strtod("1",0) != 0; }
649da2e3ebdSchin}end
650da2e3ebdSchin
651da2e3ebdSchinstd	strtold stdlib.h note{ stuck with standard strtold }end nostatic{
652da2e3ebdSchin	_BEGIN_EXTERNS_
653da2e3ebdSchin	#if _STD_
654da2e3ebdSchin	long double strtold(const char* s, char** e) { return 0.0; }
655da2e3ebdSchin	#else
656da2e3ebdSchin	long double strtold(s, e) char* s; char** e; { return 0.0; }
657da2e3ebdSchin	#endif
658da2e3ebdSchin	_END_EXTERNS_
659da2e3ebdSchin	int main() { printf(""); return strtold("1",0) != 0; }
660da2e3ebdSchin}end
661da2e3ebdSchin
662da2e3ebdSchinstd	strtol note{ stuck with standard strtol }end nostatic{
663da2e3ebdSchin	_BEGIN_EXTERNS_
664da2e3ebdSchin	#if _STD_
665da2e3ebdSchin	extern long atol(const char*);
666da2e3ebdSchin	long strtol(const char* s, char** e, int b) { return 0; }
667da2e3ebdSchin	#else
668da2e3ebdSchin	extern long atol();
669da2e3ebdSchin	long strtol(s, e, b) char* s; char** e; int b; { return 0; }
670da2e3ebdSchin	#endif
671da2e3ebdSchin	_END_EXTERNS_
672da2e3ebdSchin	int main() { printf(""); return (atol("1") + strtol("1",(char**)0,0)) != 0; }
673da2e3ebdSchin}end
674da2e3ebdSchin
675da2e3ebdSchintst	- output{
676da2e3ebdSchin	int
677da2e3ebdSchin	main()
678da2e3ebdSchin	{
679da2e3ebdSchin	#if _UWIN
680da2e3ebdSchin		printf("\n");
681da2e3ebdSchin		printf("/* override some uwin feature tests */\n");
682da2e3ebdSchin		printf("#undef	_lib_execlp\n");
683da2e3ebdSchin		printf("#undef	_lib_execvp\n");
684da2e3ebdSchin		printf("#undef	_lib_execvpe\n");
685da2e3ebdSchin		printf("#undef	_lib_fork\n");
686da2e3ebdSchin		printf("#undef	_std_string\n");
687da2e3ebdSchin		printf("#define _std_string	1\n");
688da2e3ebdSchin		printf("#undef	_stream_peek\n");
689da2e3ebdSchin		printf("\n");
690da2e3ebdSchin	#endif
691da2e3ebdSchin
692da2e3ebdSchin	#if _lib_spawnveg || _lib_posix_spawn || _lib_spawn_mode || _lib_spawn && _hdr_spawn && _mem_pgroup_inheritance || _lib_vfork && _real_vfork
693da2e3ebdSchin		printf("#if !_AST_no_spawnveg\n");
694da2e3ebdSchin		printf("#define _use_spawnveg	1\n");
695da2e3ebdSchin		printf("#endif\n");
696da2e3ebdSchin		printf("\n");
697da2e3ebdSchin	#endif
698da2e3ebdSchin
699da2e3ebdSchin		return 0;
700da2e3ebdSchin	}
701da2e3ebdSchin
702da2e3ebdSchin}end
703da2e3ebdSchin
704da2e3ebdSchintst	no64 -D_LARGEFILE64_SOURCE note{ largefile 64 broken }end execute{
705da2e3ebdSchin	#include <sys/types.h>
706da2e3ebdSchin	#include <sys/stat.h>
707da2e3ebdSchin	int
708da2e3ebdSchin	main()
709da2e3ebdSchin	{
710da2e3ebdSchin		struct stat64	st;
711da2e3ebdSchin		return !stat64(".", &st) && st.st_mode && st.st_mtime;
712da2e3ebdSchin	}
713da2e3ebdSchin}end pass{
714da2e3ebdSchin	echo "/* can we at least agree that a successful return means success? */"
715da2e3ebdSchin	echo "#undef	_lib_creat64"
716da2e3ebdSchin	echo "#undef	_lib_fstat64"
717da2e3ebdSchin	echo "#undef	_lib_fstatvfs64"
718da2e3ebdSchin	echo "#undef	_lib_ftruncate64"
719da2e3ebdSchin	echo "#undef	_lib_lseek64"
720da2e3ebdSchin	echo "#undef	_lib_lstat64"
721da2e3ebdSchin	echo "#undef	_lib_mmap64"
722da2e3ebdSchin	echo "#undef	_lib_stat64"
723da2e3ebdSchin	echo "#undef	_lib_statvfs64"
724da2e3ebdSchin	echo "#undef	_lib_truncate64"
725da2e3ebdSchin}end
726