Add help command. Remove compiled files.

This commit is contained in:
Enrico Fraccaroli
2021-10-04 11:55:18 +02:00
parent b01eccca2e
commit 5263b115bf
50 changed files with 37 additions and 1 deletions
+2 -1
View File
@@ -73,7 +73,8 @@ set(PROGRAMS
kill.c
ipcrm.c
ipcs.c
sleep.c)
sleep.c
help.c)
foreach(PROGRAM ${PROGRAMS})
# Prepare the program name.
string(REPLACE ".c" "" PROGRAM_NAME ${PROGRAM})
+32
View File
@@ -0,0 +1,32 @@
/// MentOS, The Mentoring Operating system project
/// @file help.c
/// @brief Shows the available commands.
/// @copyright (c) 2014-2021 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;
}