Develop and Download Open Source Software

Browse Subversion Repository

Diff of /trunk/teraterm/teraterm/filesys_log.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 10445 by zmatsuo, Sat Dec 31 15:31:34 2022 UTC revision 10464 by zmatsuo, Sat Jan 7 15:12:14 2023 UTC
# Line 1385  BOOL FLogOpenDialog(HINSTANCE hInst, HWN Line 1385  BOOL FLogOpenDialog(HINSTANCE hInst, HWN
1385  wchar_t *FLogGetLogFilenameBase(const wchar_t *filename)  wchar_t *FLogGetLogFilenameBase(const wchar_t *filename)
1386  {  {
1387          // ファイル名部分を抽出          // ファイル名部分を抽出
1388          wchar_t *format = ExtractFileNameW(filename);          const wchar_t *last_path_sep = wcsrchr(filename, L'\\');
1389          if (format == NULL) {          wchar_t *format;
1390                  format = wcsdup(L"");          if (last_path_sep == NULL) {
1391                    format = wcsdup(filename);
1392            }
1393            else {
1394                    format = wcsdup(last_path_sep + 1);
1395          }          }
1396    
1397          // strftime に使用できない文字を削除          // strftime に使用できない文字を削除
1398          deleteInvalidStrftimeCharW(format);          deleteInvalidStrftimeCharW(format);
1399    
1400            // 文字列長が0になった?
1401            if (format[0] == 0) {
1402                    free(format);
1403                    return wcsdup(L"");
1404            }
1405    
1406          // 現在時刻を取得          // 現在時刻を取得
1407          time_t time_local;          time_t time_local;
1408          time(&time_local);          time(&time_local);
# Line 1400  wchar_t *FLogGetLogFilenameBase(const wc Line 1410  wchar_t *FLogGetLogFilenameBase(const wc
1410          localtime_s(&tm_local, &time_local);          localtime_s(&tm_local, &time_local);
1411    
1412          // strftime()で変換          // strftime()で変換
1413          size_t len = 128;          // 文字領域は自動拡張
1414          wchar_t *formated = (wchar_t*)malloc(sizeof(wchar_t) * len);          size_t len = 32;
1415          size_t r = wcsftime(formated, len, format, &tm_local);          wchar_t *formated = NULL;
1416          if (r == 0) {          while (1) {
1417                  // エラーが返ってきた                  wchar_t *formated_realloc = (wchar_t *)realloc(formated, sizeof(wchar_t) * len);
1418                  wcscpy(formated, format);                  if (formated_realloc == NULL) {
1419                            free(format);
1420                            free(formated);
1421                            return wcsdup(L"");
1422                    }
1423                    formated = formated_realloc;
1424                    size_t r = wcsftime(formated, len, format, &tm_local);
1425                    if (r != 0) {
1426                            // フォーマットできた
1427                            break;
1428                    }
1429                    len *= 2;
1430          }          }
1431          free(format);          free(format);
1432    

Legend:
Removed from v.10445  
changed lines
  Added in v.10464

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26