Files
MentOS/programs/man.c
T
Enrico Fraccaroli (Galfurian) 1b2bc49d41 Update license and remove unused files.
2022-01-27 15:12:36 -05:00

32 lines
788 B
C

/// @file man.c
/// @brief Shows the available commands.
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
/// See LICENSE.md for details.
#include <strerror.h>
#include <sys/dirent.h>
#include <sys/unistd.h>
#include <fcntl.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
int fd = open("/bin", O_RDONLY | O_DIRECTORY, 0);
if (fd == -1) {
printf("%s: cannot access '/bin': %s\n\n", argv[0], strerror(errno));
return 1;
}
dirent_t dent;
int per_line = 0;
while (getdents(fd, &dent, sizeof(dirent_t)) == sizeof(dirent_t)) {
printf("%10s ", dent.d_name);
if (++per_line == 6) {
per_line = 0;
putchar('\n');
}
}
putchar('\n');
close(fd);
return 0;
}