1N/Atst note{ check for win32 .exe botches }end output{
1N/A #include <unistd.h>
1N/A #include <fcntl.h>
1N/A #include <sys/types.h>
1N/A #include <sys/stat.h>
1N/A static int
1N/A cp(const char* from, const char* to)
1N/A {
1N/A ssize_t n;
1N/A int fd;
1N/A int td;
1N/A struct stat fs;
1N/A char buf[1024];
1N/A
1N/A if ((fd = _open(from, O_RDONLY|O_BINARY)) < 0)
1N/A return -1;
1N/A if (_fstat(fd, &fs) || (td = _open(to, O_CREAT|O_WRONLY|O_TRUNC|O_BINARY, fs.st_mode & 0777)) < 0)
1N/A {
1N/A _close(fd);
1N/A return -1;
1N/A }
1N/A while ((n = _read(fd, buf, sizeof(buf))) > 0 && _write(td, buf, n) == n);
1N/A _close(fd);
1N/A _close(td);
1N/A return n ? -1 : 0;
1N/A }
1N/A int
1N/A main(int argc, char** argv)
1N/A {
1N/A int fd;
1N/A int fix;
1N/A struct stat st;
1N/A char buf[256];
1N/A
1N/A snprintf(buf, sizeof(buf), "rm -rf /tmp/iff-%d", getpid());
1N/A if (_mkdir(buf+7, 0755))
1N/A return 1;
1N/A if (_chdir(buf+7))
1N/A return 1;
1N/A if (cp("/bin/cat.exe", "foo.exe"))
1N/A return 1;
1N/A fix = 0;
1N/A if (_access("foo", X_OK))
1N/A fix++,printf("#define _win32_botch_access 1\n");
1N/A if (_chmod("foo", 0755))
1N/A fix++,printf("#define _win32_botch_chmod 1\n");
1N/A if (cp("/bin/cat", "bam") || _access("bam.exe", X_OK))
1N/A fix++,printf("#define _win32_botch_copy 1\n");
1N/A if (_getpagesize() != 64 * 1024)
1N/A fix++,printf("#define _win32_botch_getpagesize 1\n");
1N/A #if !__EMX__
1N/A if (_link("foo", "bar") || _access("bar.exe", X_OK))
1N/A fix++,printf("#define _win32_botch_link 1\n");
1N/A else
1N/A #endif
1N/A cp("foo.exe", "bar.exe");
1N/A if ((fd = _open("foo", O_RDONLY)) < 0)
1N/A fix++,printf("#define _win32_botch_open 1\n");
1N/A else
1N/A _close(fd);
1N/A if (_pathconf("huh", _PC_NAME_MAX) >= 0)
1N/A fix++,printf("#define _win32_botch_pathconf 1\n");
1N/A if (_rename("foo", "aha") || _access("aha.exe", X_OK))
1N/A fix++,printf("#define _win32_botch_rename 1\n");
1N/A else
1N/A _rename("foo.exe", "aha.exe");
1N/A if (_stat("bar", &st))
1N/A {
1N/A fix++,printf("#define _win32_botch_stat 1\n");
1N/A if (sizeof(st.st_ino) == 8)
1N/A printf("#define _stat _stat64\n");
1N/A }
1N/A if (_truncate("aha", 0))
1N/A fix++,printf("#define _win32_botch_truncate 1\n");
1N/A if (_unlink("bar"))
1N/A fix++,printf("#define _win32_botch_unlink 1\n");
1N/A if (_utime("aha", 0))
1N/A fix++,printf("#define _win32_botch_utime 1\n");
1N/A if (fix)
1N/A {
1N/A printf("#define _win32_botch_execve 1\n");
1N/A printf("#define _win32_botch 1\n");
1N/A }
1N/A _chdir("/tmp");
1N/A system(buf);
1N/A return 0;
1N/A }
1N/A}end
1N/A
1N/Atst win32_botch_alarm note{ win32 alarm(2) return botched }end noexecute{
1N/A #include <signal.h>
1N/A #include <unistd.h>
1N/A #include <time.h>
1N/A
1N/A static int sigalrm = 0;
1N/A
1N/A static void
1N/A handler(int sig)
1N/A {
1N/A sigalrm++;
1N/A }
1N/A int
1N/A main(int argc, char** argv)
1N/A {
1N/A signal(SIGALRM, handler);
1N/A alarm(2);
1N/A pause();
1N/A return sigalrm != 1 || alarm(0) != 0;
1N/A }
1N/A}end