Fix off-by-one in apathmax() as the path is relative to "/"

1) Use size_t * instead of long *
2) Fallback to PATH_MAX instead of BUFSIZ
3) Header cleanup
This commit is contained in:
sin 2015-03-06 23:48:37 +00:00
parent 0c2f19c210
commit 7d36a35649
5 changed files with 10 additions and 11 deletions

View File

@ -7,7 +7,7 @@ char *
agetcwd(void)
{
char *buf;
long size;
size_t size;
apathmax(&buf, &size);
if (!getcwd(buf, size))

View File

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

View File

@ -28,7 +28,7 @@ cp(const char *s1, const char *s2, int depth)
{
FILE *f1, *f2;
char *ns1, *ns2;
long size1, size2;
size_t size1, size2;
struct dirent *d;
struct stat st;
struct utimbuf ut;

View File

@ -11,11 +11,10 @@
void
enmasse(int argc, char *argv[], int (*fn)(const char *, const char *, int))
{
struct stat st;
char *buf, *dir;
int i, len;
long size;
struct stat st;
size_t dlen;
size_t size, dlen;
if (argc == 2 && !(stat(argv[1], &st) == 0 && S_ISDIR(st.st_mode))) {
fnck(argv[0], argv[1], fn, 0);

2
util.h
View File

@ -21,7 +21,7 @@
extern char *argv0;
char *agetcwd(void);
void apathmax(char **, long *);
void apathmax(char **, size_t *);
void *ecalloc(size_t, size_t);
void *emalloc(size_t);