#include <stdio.h> #include <string.h> #include <unistd.h> #include <sys/stat.h> #include <sys/types.h> #include <fcntl.h> #include <dirent.h> #ifndef DEBUG #define PDEBUG(fmt, args...)/ do{}while(0) #else #define PDEBUG(fmt, args...)/ printf("[%s:%d]"fmt, __func__, __LINE__, ##args) #endif #ifndef ERROR #define PERROR(err)/ do{}while(0) #else #define PERROR(err)/ printf("[%s:%d]/n", __func__, __LINE__);/ perror(err) #endif #define BUFFER_SIZE 1024 /* * 判断是否是目录 * @ 是目录返回1,是普通文件返回0,出错返回-1 * */ int IsDir(const char *path) { struct stat buf; if (stat(path, &buf)==-1) { PERROR("stat"); PDEBUG("path = %s/n", path); return -1; } return S_ISDIR(buf.st_mode); } /* * 创建目录 * @ 可以创建多级目录,失败返回-1 * */ int CreateDir(const