Lines Matching defs:fd
214 int fd;
226 if ((fd = sysopen(path, O_RDONLY, 0)) >= 0)
234 r = (m = sysread(fd, buf, n)) >= 2 && (buf[1] == 0x5a && (buf[0] == 0x4c || buf[0] == 0x4d) || ux && buf[0] == '#' && buf[1] == '!' && (*ux = 1) && !(ux = 0)) ? 0 : -1;
235 sysclose(fd);
692 * dup*() and exec*() fd's will not be intercepted
705 close(int fd)
712 if (fd >= 0 && fd < elementsof(exe) && exe[fd])
714 r = exe[fd]->test;
715 exe[fd]->test = 0;
716 if (r > 0 && !fstat(fd, &st) && st.st_ino == exe[fd]->ino)
718 if (r = sysclose(fd))
721 if (!stat(exe[fd]->path, &st) && st.st_ino == exe[fd]->ino)
723 snprintf(buf, sizeof(buf), "%s.exe", exe[fd]->path);
724 sysrename(exe[fd]->path, buf);
730 return sysclose(fd);
734 write(int fd, const void* buf, size_t n)
736 if (fd >= 0 && fd < elementsof(exe) && exe[fd] && exe[fd]->test < 0)
737 exe[fd]->test = n >= 2 && ((unsigned char*)buf)[1] == 0x5a && (((unsigned char*)buf)[0] == 0x4c || ((unsigned char*)buf)[0] == 0x4d) && !lseek(fd, (off_t)0, SEEK_CUR);
738 return syswrite(fd, buf, n);
746 int fd;
758 fd = sysopen(path, flags, mode);
760 if (fd < 0 && errno == ENOENT && execrate(path, buf, sizeof(buf), 0))
763 fd = sysopen(buf, flags, mode);
767 if (fd >= 0 && fd < elementsof(exe) && strlen(path) < PATH_MAX &&
770 if (!suffix(path) && !fstat(fd, &st) && (exe[fd] || (exe[fd] = (Exe_test_t*)malloc(sizeof(Exe_test_t)))))
772 exe[fd]->test = -1;
773 exe[fd]->ino = st.st_ino;
774 strcpy(exe[fd]->path, path);
780 return fd;