Skip to content

Instantly share code, notes, and snippets.

@hiroshiro
Created June 22, 2016 19:15
Show Gist options
  • Save hiroshiro/26c8c5c368eb18e05bc660b7073cc2ca to your computer and use it in GitHub Desktop.
Save hiroshiro/26c8c5c368eb18e05bc660b7073cc2ca to your computer and use it in GitHub Desktop.
コマンドls Unixプログラミングp5
#include "include/apue.h"
#include <dirent.h>
int
main(int argc, char *argv[])
{
DIR *dp;
struct dirent *dirp;
if (argc != 2)
err_quit("usage: ls directory_name");
if ((dp = opendir(argv[1])) == NULL)
err_sys("can't open %s", argv[1]);
while ((dirp = readdir(dp)) != NULL)
printf("%s\n", dirp->d_name);
closedir(dp);
exit(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment