#include #include #include #include #include "aplinks.h" #include "disp_ctr.h" int get_filetime(char *fullpathname, unsigned int *dateword, unsigned int *timeword) { struct stat fstat; struct tm *tm; stat(fullpathname, &fstat); #ifndef UNIX tm = localtime(&(fstat.st_mtimespec.ts_sec)); #else tm = localtime(&(fstat.st_mtime)); #endif *timeword = (tm->tm_hour << HOUR_SHIFT); *timeword += (tm->tm_min << MIN_SHIFT); *timeword += tm->tm_sec / 2; *dateword = (tm->tm_year - 80) << YEAR_SHIFT; *dateword += ((tm->tm_mon + 1) << MON_SHIFT); *dateword += tm->tm_mday; return 0; } int set_filetime(char *fullpathname, unsigned int dateword, unsigned int timeword) { struct tm *tms; struct utimbuf filetimebuf; time_t filetime_sec; filetime_sec = time(&filetime_sec); tms = localtime(&filetime_sec); tms->tm_sec = (timeword & SEC_MASK) * 2; tms->tm_min = (timeword & MIN_MASK) >> MIN_SHIFT; tms->tm_hour= (timeword & HOUR_MASK)>> HOUR_SHIFT; tms->tm_mday= (dateword & DAY_MASK); tms->tm_mon = ((dateword & MON_MASK) >> MON_SHIFT) - 1; tms->tm_year= ((dateword & YEAR_MASK)>> YEAR_SHIFT) + 80; /* if((dateword == 0) && (timeword == 0)){ */ if((tms->tm_year == 80) && ((tms->tm_mon + 1) == 0) && (tms->tm_mday == 0)){ displist_c_printf(4, "押されていないと思われるタイムスタンプ %02d/%02d/%02d %02d:%02d:%02d は、反映しません。\n", tms->tm_year, tms->tm_mon + 1, tms->tm_mday, tms->tm_hour, tms->tm_min, tms->tm_sec); return 1; } if((filetime_sec = mktime(tms)) != -1){ filetimebuf.actime = filetime_sec; filetimebuf.modtime= filetime_sec; if(utime(fullpathname, &filetimebuf) == 0){ displist_c_printf(4, "ファイルのタイムスタンプを %02d/%02d/%02d %02d:%02d:%02d にセットしました。\n", tms->tm_year, tms->tm_mon + 1, tms->tm_mday, tms->tm_hour, tms->tm_min, tms->tm_sec); return 0; } else{ displist_c_printf(2, "ファイルのタイムスタンプを %02d/%02d/%02d %02d:%02d:%02d にセットできませんでした。\n", tms->tm_year, tms->tm_mon + 1, tms->tm_mday, tms->tm_hour, tms->tm_min, tms->tm_sec); return -1; } } else{ displist_c_printf(2, "タイムスタンプ情報を得られませんでした。(%02d/%02d/%02d %02d:%02d:%02d)\n", tms->tm_year, tms->tm_mon + 1, tms->tm_mday, tms->tm_hour, tms->tm_min, tms->tm_sec); return -1; } }