2011-08-27 23:26:11 +02:00
|
|
|
#include <stdio.h>
|
2011-11-21 00:02:53 +01:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <string.h>
|
2011-11-21 12:19:57 +01:00
|
|
|
#include <unistd.h>
|
2011-11-22 17:26:47 +01:00
|
|
|
#include <errno.h>
|
2011-11-26 11:00:45 +01:00
|
|
|
#include <error.h>
|
2012-01-15 00:47:38 +01:00
|
|
|
#include <dirent.h>
|
2011-11-03 18:26:43 +01:00
|
|
|
|
2011-11-21 00:02:53 +01:00
|
|
|
int ls(const char* path)
|
2011-08-27 23:26:11 +02:00
|
|
|
{
|
2012-01-15 00:47:38 +01:00
|
|
|
DIR* dir = opendir(path);
|
|
|
|
if ( !dir ) { error(2, errno, "%s", path); return 2; }
|
2011-11-21 00:02:53 +01:00
|
|
|
|
|
|
|
// TODO: Hack until mountpoints work correctly.
|
2011-11-21 21:49:13 +01:00
|
|
|
if ( strcmp(path, "/") == 0 ) { printf("bin\ndev\n"); }
|
2011-11-21 00:02:53 +01:00
|
|
|
|
2012-01-15 00:47:38 +01:00
|
|
|
struct dirent* entry;
|
|
|
|
while ( (entry = readdir(dir)) )
|
2011-11-03 18:26:43 +01:00
|
|
|
{
|
2012-01-15 00:47:38 +01:00
|
|
|
printf("%s\n", entry->d_name);
|
2011-11-03 18:26:43 +01:00
|
|
|
}
|
2012-01-15 00:47:38 +01:00
|
|
|
|
|
|
|
if ( derror(dir) )
|
|
|
|
{
|
|
|
|
error(2, errno, "readdir: %s", path);
|
|
|
|
}
|
|
|
|
|
|
|
|
closedir(dir);
|
|
|
|
|
|
|
|
return 0;
|
2011-11-21 00:02:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
2011-11-21 12:19:57 +01:00
|
|
|
const size_t CWD_SIZE = 512;
|
|
|
|
char cwd[CWD_SIZE];
|
|
|
|
const char* path = getcwd(cwd, CWD_SIZE);
|
|
|
|
if ( !path ) { path = "."; }
|
|
|
|
|
2011-11-21 00:02:53 +01:00
|
|
|
if ( 1 < argc ) { path = argv[1]; }
|
2011-08-27 23:26:11 +02:00
|
|
|
|
2011-11-21 00:02:53 +01:00
|
|
|
return ls(path);
|
2011-08-27 23:26:11 +02:00
|
|
|
}
|