mirror of https://github.com/mkerrisk/man-pages
scandir.3: Improve logic of the example program
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
This commit is contained in:
parent
5e84ae6cd6
commit
9a96fb657c
|
@ -302,15 +302,17 @@ main(void)
|
|||
int n;
|
||||
|
||||
n = scandir(".", &namelist, NULL, alphasort);
|
||||
if (n < 0)
|
||||
if (n == -1) {
|
||||
perror("scandir");
|
||||
else {
|
||||
while (n\-\-) {
|
||||
printf("%s\en", namelist[n]\->d_name);
|
||||
free(namelist[n]);
|
||||
}
|
||||
free(namelist);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
while (n\-\-) {
|
||||
printf("%s\en", namelist[n]\->d_name);
|
||||
free(namelist[n]);
|
||||
}
|
||||
free(namelist);
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
.fi
|
||||
|
|
Loading…
Reference in New Issue