Skip to content

Commit

Permalink
minor code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Sigmanificient committed Apr 19, 2024
1 parent d064dd5 commit 832dc70
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
5 changes: 0 additions & 5 deletions src/ls/ls.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@

#define MIN_ALLOCATED_ENTRY (1024)

enum {
EXIT_OK = 0,
EXIT_KO = 84
};

enum {
F_ALL_FILES = 1 << 0,
F_LONG_FORM = 1 << 1,
Expand Down
4 changes: 2 additions & 2 deletions src/ls/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ int main(int argc, char **argv)

db.entries = malloc(db.size * sizeof(*db.entries));
if (db.entries == NULL)
return EXIT_KO;
return EXIT_FAILURE;
if (flags & F_DIRECTORY)
flags &= ~F_RECURSIVE;
err |= list_dirs(&db, argc, argv, flags);
free(db.entries);
return err ? EXIT_KO : EXIT_OK;
return err ? EXIT_SUCCESS : EXIT_FAILURE;
}
19 changes: 10 additions & 9 deletions src/ls/print_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,19 @@
static
void get_file_right(char bits[], entry_t *entry)
{
char *bitsp = bits;
mode_t mode = entry->stat.st_mode;
static const char *s = "-rwx";

bits[0] = s[(unsigned char)ZERO_OR(mode & S_IRUSR, 1)];
bits[1] = s[(unsigned char)ZERO_OR(mode & S_IWUSR, 2)];
bits[2] = s[(unsigned char)ZERO_OR(mode & S_IXUSR, 3)];
bits[3] = s[(unsigned char)ZERO_OR(mode & S_IRGRP, 1)];
bits[4] = s[(unsigned char)ZERO_OR(mode & S_IWGRP, 2)];
bits[5] = s[(unsigned char)ZERO_OR(mode & S_IXGRP, 3)];
bits[6] = s[(unsigned char)ZERO_OR(mode & S_IROTH, 1)];
bits[7] = s[(unsigned char)ZERO_OR(mode & S_IWOTH, 2)];
bits[8] = s[(unsigned char)ZERO_OR(mode & S_IXOTH, 3)];
*bitsp++ = s[(unsigned char)ZERO_OR(mode & S_IRUSR, 1)];
*bitsp++ = s[(unsigned char)ZERO_OR(mode & S_IWUSR, 2)];
*bitsp++ = s[(unsigned char)ZERO_OR(mode & S_IXUSR, 3)];
*bitsp++ = s[(unsigned char)ZERO_OR(mode & S_IRGRP, 1)];
*bitsp++ = s[(unsigned char)ZERO_OR(mode & S_IWGRP, 2)];
*bitsp++ = s[(unsigned char)ZERO_OR(mode & S_IXGRP, 3)];
*bitsp++ = s[(unsigned char)ZERO_OR(mode & S_IROTH, 1)];
*bitsp++ = s[(unsigned char)ZERO_OR(mode & S_IWOTH, 2)];
*bitsp++ = s[(unsigned char)ZERO_OR(mode & S_IXOTH, 3)];
if (mode & S_ISUID)
bits[1] = (mode & S_IXUSR) ? 's' : 'S';
if (mode & S_ISGID)
Expand Down

0 comments on commit 832dc70

Please sign in to comment.