mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-09-04 22:51:42 +02:00
12828: dynamically allocate 'dir' in mailstat
This commit is contained in:
parent
64d591dbac
commit
25747f7d59
2 changed files with 27 additions and 30 deletions
|
@ -1,5 +1,7 @@
|
|||
2000-09-18 Clint Adams <schizo@debian.org>
|
||||
|
||||
* 12828: Src/utils.c: dynamically allocate 'dir' in mailstat.
|
||||
|
||||
* 12827: Src/utils.c: dynamically allocate 'file' in mailstat.
|
||||
|
||||
2000-09-17 Clint Adams <schizo@debian.org>
|
||||
|
|
15
Src/utils.c
15
Src/utils.c
|
@ -3788,18 +3788,13 @@ mailstat(char *path, struct stat *st)
|
|||
struct dirent *fn;
|
||||
struct stat st_ret, st_tmp;
|
||||
static struct stat st_new_last, st_ret_last;
|
||||
char dir[PATH_MAX * 2];
|
||||
char *file;
|
||||
char *dir, *file;
|
||||
int i;
|
||||
time_t atime = 0, mtime = 0;
|
||||
|
||||
/* First see if it's a directory. */
|
||||
if ((i = stat(path, st)) != 0 || !S_ISDIR(st->st_mode))
|
||||
return i;
|
||||
if (strlen(path) > sizeof(dir) - 5) {
|
||||
errno = ENAMETOOLONG;
|
||||
return -1;
|
||||
}
|
||||
|
||||
st_ret = *st;
|
||||
st_ret.st_nlink = 1;
|
||||
|
@ -3809,17 +3804,17 @@ mailstat(char *path, struct stat *st)
|
|||
st_ret.st_mode |= S_IFREG;
|
||||
|
||||
/* See if cur/ is present */
|
||||
sprintf(dir, "%s/cur", path);
|
||||
dir = dyncat(path, "/cur");
|
||||
if (stat(dir, &st_tmp) || !S_ISDIR(st_tmp.st_mode)) return 0;
|
||||
st_ret.st_atime = st_tmp.st_atime;
|
||||
|
||||
/* See if tmp/ is present */
|
||||
sprintf(dir, "%s/tmp", path);
|
||||
dir = dyncat(path, "/tmp");
|
||||
if (stat(dir, &st_tmp) || !S_ISDIR(st_tmp.st_mode)) return 0;
|
||||
st_ret.st_mtime = st_tmp.st_mtime;
|
||||
|
||||
/* And new/ */
|
||||
sprintf(dir, "%s/new", path);
|
||||
dir = dyncat(path, "/new");
|
||||
if (stat(dir, &st_tmp) || !S_ISDIR(st_tmp.st_mode)) return 0;
|
||||
st_ret.st_mtime = st_tmp.st_mtime;
|
||||
|
||||
|
@ -3835,7 +3830,7 @@ mailstat(char *path, struct stat *st)
|
|||
|
||||
/* Loop over new/ and cur/ */
|
||||
for (i = 0; i < 2; i++) {
|
||||
sprintf(dir, "%s/%s", path, i ? "cur" : "new");
|
||||
dir = tricat(path, "/", i ? "cur" : "new");
|
||||
if ((dd = opendir(dir)) == NULL)
|
||||
return 0;
|
||||
while ((fn = readdir(dd)) != NULL) {
|
||||
|
|
Loading…
Reference in a new issue