Skip to content
This repository has been archived by the owner on Nov 27, 2018. It is now read-only.

Commit

Permalink
i think i did something?
Browse files Browse the repository at this point in the history
  • Loading branch information
david pok committed Nov 14, 2018
1 parent 96f292a commit be5dd41
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
Binary file added examples/commandline
Binary file not shown.
Binary file added examples/testdir
Binary file not shown.
Binary file added lsls/lsls
Binary file not shown.
35 changes: 35 additions & 0 deletions lsls/lsls.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <dirent.h>
#include <stdlib.h>

/**
* Main
Expand All @@ -9,10 +10,44 @@ int main(int argc, char **argv)
// Parse command line

// Open directory
DIR *pdir;
struct dirent *pent = NULL;

// if (argc > 2) {
// printf("\nERROR!");
// exit(1);
// } else if (argc == 1) {
// pdir = ".";
// } else {
// pdir = argv[1];
// }
if(argc>1)
{
pdir=opendir(argv[1]);
} else {
pdir=opendir(".");
}

pdir = opendir (".");
if (pdir == NULL)
{
printf ("\nERROR! pdir could not be initialised correctly");
exit (1);
}

// Repeatly read and print entries
while ((pent = readdir (pdir))!=NULL)
{
if (pent == NULL)
{
printf ("ERROR! pent could not be initialised correctly");
exit (3);
}
printf ("%s\n", pent->d_name);
}

// Close directory
closedir (pdir);

return 0;
}

0 comments on commit be5dd41

Please sign in to comment.