mirror of
https://github.com/jarun/nnn.git
synced 2024-11-24 11:51:27 +00:00
Error handling
This commit is contained in:
parent
c609885763
commit
1c9934ab7f
17
src/nnn.c
17
src/nnn.c
|
@ -2465,7 +2465,7 @@ static void dentfree(struct entry *dents)
|
||||||
|
|
||||||
static int dentfill(char *path, struct entry **dents)
|
static int dentfill(char *path, struct entry **dents)
|
||||||
{
|
{
|
||||||
int fd, n, count;
|
int n = 0, count;
|
||||||
ulong num_saved;
|
ulong num_saved;
|
||||||
struct dirent *dp;
|
struct dirent *dp;
|
||||||
char *namep, *pnb;
|
char *namep, *pnb;
|
||||||
|
@ -2477,15 +2477,14 @@ static int dentfill(char *path, struct entry **dents)
|
||||||
if (dirp == NULL)
|
if (dirp == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
fd = dirfd(dirp);
|
int fd = dirfd(dirp);
|
||||||
|
|
||||||
n = 0;
|
|
||||||
|
|
||||||
if (cfg.blkorder) {
|
if (cfg.blkorder) {
|
||||||
num_files = 0;
|
num_files = 0;
|
||||||
dir_blocks = 0;
|
dir_blocks = 0;
|
||||||
|
|
||||||
if (fstatat(fd, ".", &sb_path, 0) == -1) {
|
if (fstatat(fd, ".", &sb_path, 0) == -1) {
|
||||||
|
closedir(dirp);
|
||||||
printwarn();
|
printwarn();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -2522,9 +2521,11 @@ static int dentfill(char *path, struct entry **dents)
|
||||||
} else
|
} else
|
||||||
dir_blocks += ent_blocks;
|
dir_blocks += ent_blocks;
|
||||||
|
|
||||||
if (interrupted)
|
if (interrupted) {
|
||||||
|
closedir(dirp);
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
dir_blocks += (cfg.apparentsz ? sb.st_size : sb.st_blocks);
|
dir_blocks += (cfg.apparentsz ? sb.st_size : sb.st_blocks);
|
||||||
++num_files;
|
++num_files;
|
||||||
|
@ -2543,6 +2544,7 @@ static int dentfill(char *path, struct entry **dents)
|
||||||
*dents = xrealloc(*dents, total_dents * sizeof(**dents));
|
*dents = xrealloc(*dents, total_dents * sizeof(**dents));
|
||||||
if (*dents == NULL) {
|
if (*dents == NULL) {
|
||||||
free(pnamebuf);
|
free(pnamebuf);
|
||||||
|
closedir(dirp);
|
||||||
errexit();
|
errexit();
|
||||||
}
|
}
|
||||||
DPRINTF_P(*dents);
|
DPRINTF_P(*dents);
|
||||||
|
@ -2556,6 +2558,7 @@ static int dentfill(char *path, struct entry **dents)
|
||||||
pnamebuf = (char *)xrealloc(pnamebuf, namebuflen);
|
pnamebuf = (char *)xrealloc(pnamebuf, namebuflen);
|
||||||
if (pnamebuf == NULL) {
|
if (pnamebuf == NULL) {
|
||||||
free(*dents);
|
free(*dents);
|
||||||
|
closedir(dirp);
|
||||||
errexit();
|
errexit();
|
||||||
}
|
}
|
||||||
DPRINTF_P(pnamebuf);
|
DPRINTF_P(pnamebuf);
|
||||||
|
@ -2604,8 +2607,10 @@ static int dentfill(char *path, struct entry **dents)
|
||||||
else
|
else
|
||||||
num_files = num_saved;
|
num_files = num_saved;
|
||||||
|
|
||||||
if (interrupted)
|
if (interrupted) {
|
||||||
|
closedir(dirp);
|
||||||
return n;
|
return n;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
dentp->blocks = (cfg.apparentsz ? sb.st_size : sb.st_blocks);
|
dentp->blocks = (cfg.apparentsz ? sb.st_size : sb.st_blocks);
|
||||||
dir_blocks += dentp->blocks;
|
dir_blocks += dentp->blocks;
|
||||||
|
|
Loading…
Reference in a new issue