/*** gcc a.c -lrt -o a.out ***/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <sys/types.h>
#include <dirent.h>
#include <errno.h>
int MakeLogDirChk();
int MakeLogDirChk()
{
struct timespec tspec;
struct tm tm_now;
DIR *dp = NULL;
char chk_dir[256]={'\0'};
char tmp[32]={'\0'};
clock_gettime(CLOCK_REALTIME, &tspec);
localtime_r((time_t *)&tspec.tv_sec, &tm_now);
memset(tmp, 0x00, sizeof(tmp));
//strftime(tmp, sizeof(tmp), "%Y-%m-%d_%H:%M:%S", &tm_now);
strftime(tmp, sizeof(tmp), "%Y-%m-%d", &tm_now);
#if DEBUG
fprintf(stdout, "tmp[%s]\n", tmp); fflush(stdout); fflush(stdout);
#endif
memset(chk_dir, 0x00, sizeof(chk_dir));
sprintf(chk_dir, "%s", tmp);
#if DEBUG
fprintf(stdout, "chk_dir[%s]\n", chk_dir); fflush(stdout); fflush(stdout);
#endif
if( (dp = opendir(chk_dir)) == NULL ) { // opendir 에러시 NULL 리턴
if (mkdir(chk_dir, 0644) < 0) { // mkdir 에러시 -1 리턴
fprintf(stderr, "please check [%s] mkdir error [%d]=[%s]\n", chk_dir, errno, strerror(errno)); fflush(stderr);
return (-1);
}
}
else { // opendir 성공
closedir(dp);
}
return 1;
}
int main(int argc, char *argv[])
{
// ......
}