2011-05-24 08:00:30 -04:00
|
|
|
/* See LICENSE file for copyright and license details. */
|
|
|
|
#include <libgen.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/stat.h>
|
2013-03-05 15:46:48 -05:00
|
|
|
|
2011-05-24 08:00:30 -04:00
|
|
|
#include "../util.h"
|
|
|
|
|
|
|
|
void
|
|
|
|
enmasse(int argc, char **argv, int (*fn)(const char *, const char *))
|
|
|
|
{
|
|
|
|
char *buf, *dir;
|
|
|
|
int i;
|
|
|
|
long size;
|
|
|
|
struct stat st;
|
|
|
|
|
|
|
|
if(argc == 2 && !(stat(argv[1], &st) == 0 && S_ISDIR(st.st_mode))) {
|
2011-06-22 18:04:56 -04:00
|
|
|
fnck(argv[0], argv[1], fn);
|
2013-03-05 15:46:48 -05:00
|
|
|
|
2011-05-24 08:00:30 -04:00
|
|
|
return;
|
2013-03-05 15:46:48 -05:00
|
|
|
} else {
|
2011-06-22 21:08:41 -04:00
|
|
|
dir = (argc == 1) ? "." : argv[--argc];
|
2013-03-05 15:46:48 -05:00
|
|
|
}
|
2011-05-24 08:00:30 -04:00
|
|
|
|
2011-06-25 12:26:44 -04:00
|
|
|
apathmax(&buf, &size);
|
2011-05-24 08:00:30 -04:00
|
|
|
for(i = 0; i < argc; i++) {
|
2014-01-24 11:23:13 -05:00
|
|
|
if(snprintf(buf, size, "%s/%s", dir, basename(argv[i])) >= size) {
|
2013-03-05 15:46:48 -05:00
|
|
|
eprintf("%s/%s: filename too long\n", dir,
|
|
|
|
basename(argv[i]));
|
|
|
|
}
|
2011-06-22 18:04:56 -04:00
|
|
|
fnck(argv[i], buf, fn);
|
2011-05-24 08:00:30 -04:00
|
|
|
}
|
|
|
|
free(buf);
|
|
|
|
}
|
2013-03-05 15:46:48 -05:00
|
|
|
|