Remove apathmax() and implicitly agetcwd()

pathconf() is just an insane interface to use. All sane operating-
systems set sane values for PATH_MAX. Due to the by-runtime-nature of
pathconf(), it actually weakens the programs depending on its values.

Given over 3 years it has still not been possible to implement a sane
and easy to use apathmax()-utility-function, and after discussing this
on IRC, we'll dump this garbage.

We are careful enough not to overflow PATH_MAX and even if, any user
is able to set another limit in config.mk if he so desires.
This commit is contained in:
FRIGN
2015-03-18 15:20:35 +01:00
parent 833670e06c
commit a68c2a9e6e
8 changed files with 17 additions and 67 deletions

View File

@@ -1,18 +0,0 @@
/* See LICENSE file for copyright and license details. */
#include <unistd.h>
#include "../util.h"
char *
agetcwd(void)
{
char *buf;
size_t size;
apathmax(&buf, &size);
if (!getcwd(buf, size))
eprintf("getcwd:");
return buf;
}

View File

@@ -1,22 +0,0 @@
/* See LICENSE file for copyright and license details. */
#include <errno.h>
#include <limits.h>
#include <unistd.h>
#include "../util.h"
void
apathmax(char **p, size_t *size)
{
errno = 0;
if ((*size = pathconf("/", _PC_PATH_MAX)) < 0) {
if (errno == 0) {
*size = PATH_MAX;
} else {
eprintf("pathconf:");
}
} else {
(*size)++;
}
*p = emalloc(*size);
}

View File

@@ -27,8 +27,7 @@ int
cp(const char *s1, const char *s2, int depth)
{
FILE *f1, *f2;
char *ns1, *ns2;
size_t size1, size2;
char ns1[PATH_MAX], ns2[PATH_MAX];
struct dirent *d;
struct stat st;
struct utimbuf ut;
@@ -71,17 +70,15 @@ cp(const char *s1, const char *s2, int depth)
if (mkdir(s2, st.st_mode) < 0 && errno != EEXIST)
eprintf("mkdir %s:", s2);
apathmax(&ns1, &size1);
apathmax(&ns2, &size2);
while ((d = readdir(dp))) {
if (strcmp(d->d_name, ".") && strcmp(d->d_name, "..")) {
r = snprintf(ns1, size1, "%s/%s", s1, d->d_name);
if (r >= size1 || r < 0) {
r = snprintf(ns1, sizeof(ns1), "%s/%s", s1, d->d_name);
if (r >= sizeof(ns1) || r < 0) {
eprintf("%s/%s: filename too long\n",
s1, d->d_name);
}
r = snprintf(ns2, size2, "%s/%s", s2, d->d_name);
if (r >= size2 || r < 0) {
r = snprintf(ns2, sizeof(ns2), "%s/%s", s2, d->d_name);
if (r >= sizeof(ns2) || r < 0) {
eprintf("%s/%s: filename too long\n",
s2, d->d_name);
}
@@ -89,8 +86,6 @@ cp(const char *s1, const char *s2, int depth)
}
}
closedir(dp);
free(ns1);
free(ns2);
goto preserve;
}

View File

@@ -12,9 +12,9 @@ void
enmasse(int argc, char *argv[], int (*fn)(const char *, const char *, int))
{
struct stat st;
char *buf, *dir;
char buf[PATH_MAX], *dir;
int i, len;
size_t size, dlen;
size_t dlen;
if (argc == 2 && !(stat(argv[1], &st) == 0 && S_ISDIR(st.st_mode))) {
fnck(argv[0], argv[1], fn, 0);
@@ -23,18 +23,16 @@ enmasse(int argc, char *argv[], int (*fn)(const char *, const char *, int))
dir = (argc == 1) ? "." : argv[--argc];
}
apathmax(&buf, &size);
for (i = 0; i < argc; i++) {
dlen = strlen(dir);
if (dlen > 0 && dir[dlen - 1] == '/')
len = snprintf(buf, size, "%s%s", dir, basename(argv[i]));
len = snprintf(buf, sizeof(buf), "%s%s", dir, basename(argv[i]));
else
len = snprintf(buf, size, "%s/%s", dir, basename(argv[i]));
if (len < 0 || len >= size) {
len = snprintf(buf, sizeof(buf), "%s/%s", dir, basename(argv[i]));
if (len < 0 || len >= sizeof(buf)) {
eprintf("%s/%s: filename too long\n", dir,
basename(argv[i]));
}
fnck(argv[i], buf, fn, 0);
}
free(buf);
}