/* Simple (very) version of POSIX ls command (ls-lite) to show POSIX directory browsing functions in action. Author: Kevlin Henney (kevlin@acm.org, kevlin@curbralan.com) History: Created March 1997. Updated February 2003. Rights: See end of file. */ #include #include #include #include #include int main(int argc, char *argv[]) { const char *where = argc > 1 ? argv[1] : "."; DIR *dir; errno = 0; if((dir = opendir(where)) != 0) { struct dirent *entry; while((entry = readdir(dir)) != 0) { puts(entry->d_name); } errno = 0; closedir(dir); } if(errno != 0) { fprintf(stderr, "Error: %s: %s\n", where, strerror(errno)); } return errno; } /* Copyright Kevlin Henney, 1997, 2003. All rights reserved. Permission to use, copy, modify, and distribute this software and its documentation for any purpose is hereby granted without fee, provided that this copyright and permissions notice appear in all copies and derivatives. This software is supplied "as is" without express or implied warranty. But that said, if there are any problems please get in touch. */