get directory contents
This commit is contained in:
1 parent
ef7b09cbeb
commit
7b1511e31a
2 files changed
+50
-3
No files matched your search
@@ -7,7 +7,7 @@ int log_info( const char* format, ... )
|
||||
va_list args;
|
||||
|
||||
va_start( args, format );
|
||||
result = fprintf( stdout, format, args );
|
||||
result = vfprintf( stdout, format, args );
|
||||
va_end( args );
|
||||
|
||||
( void )fputc('\n', stdout);
|
||||
@@ -21,7 +21,7 @@ int log_error( const char* format, ... )
|
||||
va_list args;
|
||||
|
||||
va_start( args, format );
|
||||
result = fprintf( stderr, format, args );
|
||||
result = vfprintf( stderr, format, args );
|
||||
va_end( args );
|
||||
|
||||
( void )fputc('\n', stderr);
|
||||
|
||||
+48
-1
@@ -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( ¤t_directory[0], PATH_MAX ) )
|
||||
// {
|
||||
// log_info( "current directory: %s", current_directory );
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// log_error( "failed to get the current directory" );
|
||||
// return -1;
|
||||
// }
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user