xref: /titanic_44/usr/src/lib/libast/common/features/omitted (revision 4557a2a1868181b517f5dfe61ba6eeba58edf4c0)
1tst	note{ check for win32 .exe botches }end output{
2	#include <unistd.h>
3	#include <fcntl.h>
4	#include <sys/types.h>
5	#include <sys/stat.h>
6	static int
7	cp(const char* from, const char* to)
8	{
9		ssize_t		n;
10		int		fd;
11		int		td;
12		struct stat	fs;
13		char		buf[1024];
14
15		if ((fd = _open(from, O_RDONLY|O_BINARY)) < 0)
16			return -1;
17		if (_fstat(fd, &fs) || (td = _open(to, O_CREAT|O_WRONLY|O_TRUNC|O_BINARY, fs.st_mode & 0777)) < 0)
18		{
19			_close(fd);
20			return -1;
21		}
22		while ((n = _read(fd, buf, sizeof(buf))) > 0 && _write(td, buf, n) == n);
23		_close(fd);
24		_close(td);
25		return n ? -1 : 0;
26	}
27	int
28	main(int argc, char** argv)
29	{
30		int		fd;
31		int		fix;
32		struct stat	st;
33		char		buf[256];
34
35		snprintf(buf, sizeof(buf), "rm -rf /tmp/iff-%d", getpid());
36		if (_mkdir(buf+7, 0755))
37			return 1;
38		if (_chdir(buf+7))
39			return 1;
40		if (cp("/bin/cat.exe", "foo.exe"))
41			return 1;
42		fix = 0;
43		if (_access("foo", X_OK))
44			fix++,printf("#define _win32_botch_access	1\n");
45		if (_chmod("foo", 0755))
46			fix++,printf("#define _win32_botch_chmod	1\n");
47		if (cp("/bin/cat", "bam") || _access("bam.exe", X_OK))
48			fix++,printf("#define _win32_botch_copy	1\n");
49		if (_getpagesize() != 64 * 1024)
50			fix++,printf("#define _win32_botch_getpagesize	1\n");
51	#if !__EMX__
52		if (_link("foo", "bar") || _access("bar.exe", X_OK))
53			fix++,printf("#define _win32_botch_link	1\n");
54		else
55	#endif
56			cp("foo.exe", "bar.exe");
57		if ((fd = _open("foo", O_RDONLY)) < 0)
58			fix++,printf("#define _win32_botch_open	1\n");
59		else
60			_close(fd);
61		if (_pathconf("huh", _PC_NAME_MAX) >= 0)
62			fix++,printf("#define _win32_botch_pathconf	1\n");
63		if (_rename("foo", "aha") || _access("aha.exe", X_OK))
64			fix++,printf("#define _win32_botch_rename	1\n");
65		else
66			_rename("foo.exe", "aha.exe");
67		if (_stat("bar", &st))
68		{
69			fix++,printf("#define _win32_botch_stat	1\n");
70			if (sizeof(st.st_ino) == 8)
71				printf("#define _stat			_stat64\n");
72		}
73		if (_truncate("aha", 0))
74			fix++,printf("#define _win32_botch_truncate	1\n");
75		if (_unlink("bar"))
76			fix++,printf("#define _win32_botch_unlink	1\n");
77		if (_utime("aha", 0))
78			fix++,printf("#define _win32_botch_utime	1\n");
79		if (fix)
80		{
81			printf("#define _win32_botch_execve	1\n");
82			printf("#define _win32_botch	1\n");
83		}
84		_chdir("/tmp");
85		system(buf);
86		return 0;
87	}
88}end
89
90tst	win32_botch_alarm note{ win32 alarm(2) return botched }end noexecute{
91	#include <signal.h>
92	#include <unistd.h>
93	#include <time.h>
94
95	static int	sigalrm = 0;
96
97	static void
98	handler(int sig)
99	{
100		sigalrm++;
101	}
102	int
103	main(int argc, char** argv)
104	{
105		signal(SIGALRM, handler);
106		alarm(2);
107		pause();
108		return sigalrm != 1 || alarm(0) != 0;
109	}
110}end
111