added positional argument, started experimenting with lstat()
This commit is contained in:
1 parent
c87dd241a0
commit
0455ebaa40
3 files changed
+36
-18
No files matched your search
+8
-17
@@ -6,6 +6,7 @@
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <linux/limits.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
// internal dependencies
|
||||
#include "log.h"
|
||||
@@ -20,42 +21,32 @@ int main( int argc, char** argv )
|
||||
|
||||
parse_args( argc, argv, &args );
|
||||
|
||||
char argument_directory[ PATH_MAX ] = ".";
|
||||
DIR* directory = opendir( argument_directory );
|
||||
DIR* directory = opendir( args.path );
|
||||
struct dirent* entry;
|
||||
|
||||
if ( !directory )
|
||||
{
|
||||
if ( ENOENT == errno )
|
||||
log_error( "no directory `%s`", argument_directory );
|
||||
log_error( "no directory `%s`", args.path );
|
||||
else
|
||||
log_error( "failed to open directory `%s`", argument_directory );
|
||||
log_error( "failed to open directory `%s`", args.path );
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
while ( NULL != ( entry = readdir( directory ) ) )
|
||||
{
|
||||
char full_path[ PATH_MAX ]; // TODO: assemble full path
|
||||
struct stat status = { 0 };
|
||||
if ( !args.show_all && ( !strncmp( entry->d_name, ".", 1) || !strncmp( entry->d_name, "..", 2 ) ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
log_info( "%s", entry->d_name );
|
||||
// if ( lstat( ) ) // TODO: get file stats
|
||||
log_info( "%s: %c", entry->d_name, entry->d_type );
|
||||
}
|
||||
|
||||
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