Opendir
Open a directory
Name : opendir
Function : ディレクトリを開く.
#include <sys/types.h>
#include <dirent.h>
DIR *opendir(const char *name);
DIR *fdopendir(int fd);
Error : NULL and errno
LinuxベースのC言語を用いたシステムコールの利用方法.
Open a directory
Name : opendir
Function : ディレクトリを開く.
#include <sys/types.h>
#include <dirent.h>
DIR *opendir(const char *name);
DIR *fdopendir(int fd);
Error : NULL and errno
ディレクトリを開くプログラム.
#include<stdio.h>
#include<stdlib.h>
#include<sys/types.h>
#include<dirent.h>
int main(int argc, char **argv)
{
if(argc < 2) {
fprintf(stderr, "usage: %s Directory Name.\n", argv[0]);
exit(EXIT_FAILURE);
}
DIR *opndir;
if((opndir = opendir(argv[1])) == NULL) {
perror("opendir");
exit(EXIT_FAILURE);
}
else {
printf("Success\n");
closedir(opndir);
}
return 0;
}
実行例
$ ./opendir ~/
Success
$ ./opendir null
opendir: No such file or directory