Very old versions for history.
[opsoft_archive.git] / silentbob / silent_bob-1.2 / src / sblib / find.cpp
blob6cf956a9d452e9fb32937a71ca70304ef76dfc41
1 /*
2 * (c) Oleg Puchinin 2006
3 * graycardinalster@gmail.com
4 *
5 */
7 #include "../head.h"
8 #include <sys/wait.h>
10 int sblib_find (char * path, char * name, char * f_outname)
12 int devnull;
13 int fd;
14 int pid;
15 int status = -1;
17 pid = fork ();
18 if (pid == 0) {
19 devnull = open ("/dev/null", O_WRONLY, 0600);
20 fd = open (f_outname, O_WRONLY, 0600);
21 if (fd == -1) {
22 fd = open (f_outname, O_WRONLY | O_CREAT, 0600);
23 if (fd == -1) {
24 close (devnull);
25 return -1;
27 } else
28 lseek (fd, 0, SEEK_END);
29 dup2 (devnull, 2);
30 dup2 (fd, 1);
31 execlp ("find", path, "-name", name, NULL);
32 } else if (pid > 0) {
33 waitpid (pid, &status, 0);
34 close (fd);
35 return status;
38 return status;