Linux
파일에 수정 시간 가져오기
aucd29
2013. 9. 26. 20:56
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//
// get file modify time
//
char* getModifyTime(char *path)
{
FILE *fp;
unsigned int chk=0, i=0;
char tmp[200],cmd[100],c;
char *out;
sprintf(cmd, "stat %s | grep Modify: > /tmp/msgLogFile", path);
system(cmd);
fp = fopen("/tmp/msgLogFile", "r");
if(!fp) exit(1);
while((c=getc(fp))!=EOF)
{
if(i>7)
tmp[chk++] = c;
else
i++;
}
tmp[chk-1]='\0';
out = (char*)malloc(strlen(tmp));
strcpy(out, tmp);
return out;
}
int main(void)
{
char *time;
time = getModifyTime("./messages");
printf("%s \n", time);
free(time);
return 1;
}
#include <stdlib.h>
#include <string.h>
//
// get file modify time
//
char* getModifyTime(char *path)
{
FILE *fp;
unsigned int chk=0, i=0;
char tmp[200],cmd[100],c;
char *out;
sprintf(cmd, "stat %s | grep Modify: > /tmp/msgLogFile", path);
system(cmd);
fp = fopen("/tmp/msgLogFile", "r");
if(!fp) exit(1);
while((c=getc(fp))!=EOF)
{
if(i>7)
tmp[chk++] = c;
else
i++;
}
tmp[chk-1]='\0';
out = (char*)malloc(strlen(tmp));
strcpy(out, tmp);
return out;
}
int main(void)
{
char *time;
time = getModifyTime("./messages");
printf("%s \n", time);
free(time);
return 1;
}