Skip to content

Commit

Permalink
Improve getopt_long call
Browse files Browse the repository at this point in the history
  • Loading branch information
Sigmanificient committed Apr 24, 2024
1 parent f50ebba commit 752e6b7
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/ls/ls_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ static const struct option LONG_OPTIONS[] = {

static char compose_flaglist(int argc, char **argv) {
char flags = 0;
int oi = -1;

for (;;) {
int c = getopt_long(argc, argv, "alRdrt", LONG_OPTIONS, &oi);
int c = getopt_long(argc, argv, "alRdrt", LONG_OPTIONS, NULL);

if (c == -1)
return flags;
Expand All @@ -49,6 +48,7 @@ static char compose_flaglist(int argc, char **argv) {
break;
case 'd':
flags |= F_DIRECTORY;
flags &= ~F_RECURSIVE;
break;
case 'r':
flags |= F_REV_ORDER;
Expand Down Expand Up @@ -101,8 +101,6 @@ int main(int argc, char **argv) {
db.entries = malloc(db.size * sizeof(*db.entries));
if (db.entries == NULL)
return EXIT_FAILURE;
if (flags & F_DIRECTORY)
flags &= ~F_RECURSIVE;
err |= !list_dirs(&db, argc, argv, flags);
free(db.entries);
return err ? EXIT_SUCCESS : EXIT_FAILURE;
Expand Down

0 comments on commit 752e6b7

Please sign in to comment.