get directory contents

This commit is contained in:
root committed 2026-06-21 23:11:31 +02:00
1 parent ef7b09cbeb
commit 7b1511e31a
2 files changed
+50 -3

No files matched your search

+48 -1
View File
@@ -1,11 +1,58 @@
#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include <dirent.h>
#include <linux/limits.h>
#include "log.h"
typedef struct dirent dirent;
int main( int argc, char** argv )
{
( void )argc;
( void )argv;
log_info( "kuckuck!" );
if ( 2 < argc ) return -1;
char argument_directory[ PATH_MAX ];
if ( 2 == argc )
{
strcpy( argument_directory, argv[1] );
}
else
{
argument_directory[0] = '.';
argument_directory[1] = '\0';
}
DIR* directory = opendir( argument_directory );
dirent* entry;
if ( !directory )
{
log_error( "failed to open directory `%s`", argument_directory );
return -1;
}
while ( NULL != ( entry = readdir( directory ) ) )
{
log_info( "%s", entry->d_name );
}
closedir( directory );
// char current_directory[ PATH_MAX ];
//
// if ( NULL != getcwd( &current_directory[0], PATH_MAX ) )
// {
// log_info( "current directory: %s", current_directory );
// }
// else
// {
// log_error( "failed to get the current directory" );
// return -1;
// }
return 0;
}