add ln, util.a
This commit is contained in:
38
util/enmasse.c
Normal file
38
util/enmasse.c
Normal file
@@ -0,0 +1,38 @@
|
||||
/* 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>
|
||||
#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))) {
|
||||
if(fn(argv[0], argv[1]) != 0)
|
||||
eprintf("%s:", argv[1]);
|
||||
return;
|
||||
}
|
||||
else if(argc == 1)
|
||||
dir = ".";
|
||||
else
|
||||
dir = argv[--argc];
|
||||
|
||||
if((size = pathconf(dir, _PC_PATH_MAX)) < 0)
|
||||
size = BUFSIZ;
|
||||
if(!(buf = malloc(size)))
|
||||
eprintf("malloc:");
|
||||
for(i = 0; i < argc; i++) {
|
||||
snprintf(buf, size, "%s/%s", dir, basename(argv[i]));
|
||||
if(fn(argv[i], buf) != 0)
|
||||
eprintf("%s:", buf);
|
||||
}
|
||||
free(buf);
|
||||
}
|
22
util/eprintf.c
Normal file
22
util/eprintf.c
Normal file
@@ -0,0 +1,22 @@
|
||||
/* See LICENSE file for copyright and license details. */
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "../util.h"
|
||||
|
||||
void
|
||||
eprintf(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
vfprintf(stderr, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
if(fmt[0] && fmt[strlen(fmt)-1] == ':') {
|
||||
fputc(' ', stderr);
|
||||
perror(NULL);
|
||||
}
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
Reference in New Issue
Block a user