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