.
This commit is contained in:
commit
55385f8857
69 changed files with 1125 additions and 0 deletions
60
fetcher/fetcher.c
Normal file
60
fetcher/fetcher.c
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
#include <unistd.h>
|
||||
#include <libowfat/errmsg.h>
|
||||
#include <libowfat/buffer.h>
|
||||
#include <sys/wait.h>
|
||||
#include "fetcher.h"
|
||||
|
||||
#define dieusage() die(100, "usage: ", argv0, " [-v] [-j jobs] URL...\n\
|
||||
(-v means verbose)")
|
||||
|
||||
int verbose = 0;
|
||||
int jobs = 5;
|
||||
|
||||
int queuepipe[2];
|
||||
/* merged stdout of workers */
|
||||
int errpipe[2];
|
||||
/* merged stderr of workers */
|
||||
int outpipe[2];
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
errmsg_iam(*argv);
|
||||
int i;
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (argv[i][0] != '-') break;
|
||||
if (argv[i][1] == '-' && !argv[i][2]) break;
|
||||
switch (argv[i][1]) {
|
||||
case 'j':
|
||||
i++;
|
||||
jobs = atoi(argv[i]);
|
||||
if (jobs < 1)
|
||||
die(100, "value for -n must be >= 1");
|
||||
break;
|
||||
case 'v':
|
||||
verbose = 1;
|
||||
break;
|
||||
default: dieusage();
|
||||
}
|
||||
}
|
||||
argc -= i;
|
||||
argv += i;
|
||||
if (argc < 1) dieusage();
|
||||
|
||||
if (pipe(errpipe)<0
|
||||
|| pipe(outpipe)<0
|
||||
) diesys(111, "pipe");
|
||||
|
||||
if (verbose) {
|
||||
buffer_puts(buffer_2, "Using ");
|
||||
buffer_putlong(buffer_2, jobs);
|
||||
buffer_puts(buffer_2, " parallel jobs\n");
|
||||
buffer_flush(buffer_2);
|
||||
}
|
||||
|
||||
char **fetchcmd = (char *[]){"curl", "-o", "a.txt", "https://lab0x13.site/index.html", NULL};
|
||||
pid_t pid = spawnchild(fetchcmd, outpipe[1], errpipe[1]);
|
||||
if (pid<0)
|
||||
exit(111);
|
||||
waitpid(pid, NULL, 0);
|
||||
exit(0);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue