一个C文件:listdir.c,一个Makefile文件.
//file: listdir.c
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <dirent.h>
#include <errno.h>
#ifdef __cplusplus
extern "C" {
#endif
#define MAX_PATH_LEN 256
int main(void)
{
char path[MAX_PATH_LEN] = {0};
DIR *dir = NULL;
struct dirent *ptr = NULL;
printf("Please input the path:");
scanf("%s", path);
if( NULL == (dir = opendir(path)) )
{
switch(errno)
{
case EACCES:
{
printf("No premium to access %s ...\n", path);
/*Add code here*/
}
break;
case ENFILE: