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