summaryrefslogtreecommitdiff
path: root/Src/utils.c
diff options
context:
space:
mode:
authorClint Adams <clint@users.sourceforge.net>2000-09-18 03:52:59 +0000
committerClint Adams <clint@users.sourceforge.net>2000-09-18 03:52:59 +0000
commit64d591dbac0a66814b04cce03c409184a4831096 (patch)
tree74dcd3766f403f5cd130be973ca1e69687435d84 /Src/utils.c
parent2d9e68f3cbd7fe817fa3a204d1a55ac79980abeb (diff)
downloadzsh-64d591dbac0a66814b04cce03c409184a4831096.tar.gz
zsh-64d591dbac0a66814b04cce03c409184a4831096.zip
12827: dynamically allocate 'file' in mailstat
Diffstat (limited to 'Src/utils.c')
-rw-r--r--Src/utils.c38
1 files changed, 18 insertions, 20 deletions
diff --git a/Src/utils.c b/Src/utils.c
index ca46fd870..603d3a4ee 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -3789,8 +3789,8 @@ mailstat(char *path, struct stat *st)
struct stat st_ret, st_tmp;
static struct stat st_new_last, st_ret_last;
char dir[PATH_MAX * 2];
- char file[PATH_MAX * 2];
- int i, l;
+ char *file;
+ int i;
time_t atime = 0, mtime = 0;
/* First see if it's a directory. */
@@ -3832,28 +3832,26 @@ mailstat(char *path, struct stat *st)
return 0;
}
st_new_last = st_tmp;
-
+
/* Loop over new/ and cur/ */
for (i = 0; i < 2; i++) {
- sprintf(dir, "%s/%s", path, i ? "cur" : "new");
- sprintf(file, "%s/", dir);
- l = strlen(file);
+ sprintf(dir, "%s/%s", path, i ? "cur" : "new");
if ((dd = opendir(dir)) == NULL)
- return 0;
+ return 0;
while ((fn = readdir(dd)) != NULL) {
- if (fn->d_name[0] == '.' ||
- strlen(fn->d_name) + l >= sizeof(file))
- continue;
- strcpy(file + l, fn->d_name);
- if (stat(file, &st_tmp) != 0)
- continue;
- st_ret.st_size += st_tmp.st_size;
- st_ret.st_blocks++;
- if (st_tmp.st_atime != st_tmp.st_mtime &&
- st_tmp.st_atime > atime)
- atime = st_tmp.st_atime;
- if (st_tmp.st_mtime > mtime)
- mtime = st_tmp.st_mtime;
+ if (fn->d_name[0] == '.')
+ continue;
+
+ file = zhtricat(dir, "/", fn->d.name);
+ if (stat(file, &st_tmp) != 0)
+ continue;
+ st_ret.st_size += st_tmp.st_size;
+ st_ret.st_blocks++;
+ if (st_tmp.st_atime != st_tmp.st_mtime &&
+ st_tmp.st_atime > atime)
+ atime = st_tmp.st_atime;
+ if (st_tmp.st_mtime > mtime)
+ mtime = st_tmp.st_mtime;
}
closedir(dd);
}