/* Modified code from afio https://github.com/kholtman/afio/blob/master/afio.c */ /* - The main authors and maintainers all intend afio to be free and * freely distributable. It has been distributed widely and for * free since at least 1987, when it was posted to the * comp.sources.unix newsgroup. * * - The legal risks to re-distributers, coming from the licence, are * effectively zero. * * - The afio license is not a standard OSI/FSF approved free software * license, it predates these license texts. Unfortunately, the * afio license includes wording that is considered to be * problematic by several of todays open source licensing legal * experts, because the wording leaves too much room for * interpretation. It is impossible to upgrade this problematic * license text. * * - Therefore, if your software redistribution or package labeling * policy implies a rejection of non-standard OSI/FSF approved free * software licenses, you need to be careful about handling afio. * * See the file afio_license_issues_v5.txt for more legal * discussion. */ #include #include #include #include #include #include #include /* * mkdir() * * Make a directory via "/bin/mkdir". Sets errno to a * questionably sane value upon failure. */ int mkdir (name, mode) char *name; ushort mode; { int pid; int status; if ((pid = fork ()) == 0) { close (fileno (stdin)); close (fileno (stdout)); close (fileno (stderr)); open ("/dev/null", O_RDWR); dup (fileno (stdin)); dup (fileno (stdin)); umask (~mode); execl ("/bin/mkdir", "mkdir", name, (char *) NULL); exit (-1); } if (wait(&status) >= 0) { if ((status & 0xffff) == 0) return (0); } errno = EACCES; return (-1); } /* * rmdir() * * Remove a directory via "/bin/rmdir". Sets errno to a * questionably sane value upon failure. */ int rmdir (name) char *name; { int pid; int status; if ((pid = fork ()) == 0) { close (fileno (stdin)); close (fileno (stdout)); close (fileno (stderr)); open ("/dev/null", O_RDWR); dup (fileno (stdin)); dup (fileno (stdin)); execl ("/bin/rmdir", "rmdir", name, (char *) NULL); exit (-1); } if (wait(&status) >= 0) { if ((status & 0xffff) == 0) return (0); } errno = EACCES; return (-1); } int remove(char *fn) { int rc; if ((rc = unlink(fn)) == -1) { rc = rmdir(fn); } } int rename(char *from, char *to) { int pid; int status; if ((pid = fork ()) == 0) { close (fileno (stdin)); close (fileno (stdout)); close (fileno (stderr)); open ("/dev/null", O_RDWR); dup (fileno (stdin)); dup (fileno (stdin)); execl ("/bin/mv", "mv", from, to, (char *) NULL); exit (-1); } if (wait(&status) >= 0) { if ((status & 0xffff) == 0) return (0); } errno = EACCES; return (-1); }