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