37 lines
683 B
C
37 lines
683 B
C
#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;
|
|
}
|