'
This commit is contained in:
parent
ce214b8bbd
commit
9dabdcfbfd
5 changed files with 82 additions and 1 deletions
37
simple_ls/simple_ls.c
Normal file
37
simple_ls/simple_ls.c
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
#include <dirent.h>
|
||||
#include <err.h>
|
||||
#include <stdio.h>
|
||||
|
||||
static void simple_ls(char *path)
|
||||
{
|
||||
if (path == NULL)
|
||||
errx(1, "Internal error: Passed NULL path");
|
||||
|
||||
DIR *dir = opendir(path);
|
||||
if (dir == NULL)
|
||||
errx(1, "Internal error: cannot open directory");
|
||||
|
||||
struct dirent *element;
|
||||
while ((element = readdir(dir)))
|
||||
{
|
||||
puts(element->d_name);
|
||||
}
|
||||
|
||||
int res = closedir(dir);
|
||||
if (res == -1)
|
||||
errx(1, "Could not close dir");
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (argc < 2)
|
||||
simple_ls(".");
|
||||
else
|
||||
{
|
||||
for (int i = 1; i < argc; i++)
|
||||
{
|
||||
simple_ls(argv[i]);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue