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