X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=dir.c;h=5a40d8ff8c99c80bf8f0484425db6022c6f7d8e9;hb=2886bdb118699fbc343e3c0b4f93f06fbeae1061;hp=d778ecd8908d7a32519cc9c31d8333de3fad0ae6;hpb=e96b6c4bf6dab94fd3833c31adc5105589a59e7a;p=git.git diff --git a/dir.c b/dir.c index d778ecd89..5a40d8ff8 100644 --- a/dir.c +++ b/dir.c @@ -101,8 +101,8 @@ void add_exclude(const char *string, const char *base, x->baselen = baselen; if (which->nr == which->alloc) { which->alloc = alloc_nr(which->alloc); - which->excludes = realloc(which->excludes, - which->alloc * sizeof(x)); + which->excludes = xrealloc(which->excludes, + which->alloc * sizeof(x)); } which->excludes[which->nr++] = x; } @@ -112,17 +112,15 @@ static int add_excludes_from_file_1(const char *fname, int baselen, struct exclude_list *which) { + struct stat st; int fd, i; long size; char *buf, *entry; fd = open(fname, O_RDONLY); - if (fd < 0) + if (fd < 0 || fstat(fd, &st) < 0) goto err; - size = lseek(fd, 0, SEEK_END); - if (size < 0) - goto err; - lseek(fd, 0, SEEK_SET); + size = st.st_size; if (size == 0) { close(fd); return 0; @@ -293,7 +291,7 @@ static int read_directory_recursive(struct dir_struct *dir, const char *path, co if (fdir) { int exclude_stk; struct dirent *de; - char fullname[MAXPATHLEN + 1]; + char fullname[PATH_MAX + 1]; memcpy(fullname, base, baselen); exclude_stk = push_exclude_per_directory(dir, base, baselen); @@ -336,7 +334,7 @@ static int read_directory_recursive(struct dir_struct *dir, const char *path, co if (dir->show_other_directories && (subdir || !dir->hide_empty_directories) && !dir_exists(fullname, baselen + len)) { - // Rewind the read subdirectory + /* Rewind the read subdirectory */ while (dir->nr > rewind_base) free(dir->entries[--dir->nr]); break;