Very old versions for history.
[opsoft_archive.git] / silentbob / silentbob-1.1 / src / sblib / find.cpp
bloba438a99040821defa854161a821d9000595b0daa
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 return status;
37 return status;