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 5141 by maya, Sat Mar 9 15:07:56 2013 UTC revision 5162 by yutakapon, Sat Mar 23 09:03:14 2013 UTC
# Line 22  Line 22 
22  #include "filesys.h"  #include "filesys.h"
23  #include "ftlib.h"  #include "ftlib.h"
24    
25    #include <io.h>
26    
27  #define FS_BRACKET_NONE  0  #define FS_BRACKET_NONE  0
28  #define FS_BRACKET_START 1  #define FS_BRACKET_START 1
29  #define FS_BRACKET_END   2  #define FS_BRACKET_END   2
# Line 530  BOOL LogStart() Line 532  BOOL LogStart()
532          }          }
533          LogVar->ByteCount = 0;          LogVar->ByteCount = 0;
534    
535            LogVar->RotateMode = ROTATE_NONE;
536    
537          if (! OpenFTDlg(LogVar)) {          if (! OpenFTDlg(LogVar)) {
538                  FileTransEnd(OpLog);                  FileTransEnd(OpLog);
539                  return FALSE;                  return FALSE;
# Line 647  void CommentLogToFile(char *buf, int siz Line 651  void CommentLogToFile(char *buf, int siz
651          logfile_unlock();          logfile_unlock();
652  }  }
653    
654    // ログをローテートする。
655    // (2013.3.21 yutaka)
656    static void LogRotate(void)
657    {
658            const int loopmax = 10000;  // XXX
659            char filename[1024];
660            int i;
661            int dwShareMode = 0;
662    
663            if (! LogVar->FileOpen) return;
664    
665            if (LogVar->RotateMode == ROTATE_NONE)
666                    return;
667    
668            if (LogVar->RotateMode == ROTATE_SIZE) {
669                    if (LogVar->ByteCount <= LogVar->RotateSize)
670                            return;
671                    //OutputDebugPrintf("%s: mode %d size %ld\n", __FUNCTION__, LogVar->RotateMode, LogVar->ByteCount);
672            } else {
673                    return;
674            }
675    
676            logfile_lock();
677            // ログサイズを再初期化する。
678            LogVar->ByteCount = 0;
679    
680            // いったん今のファイルをクローズして、別名のファイルをオープンする。
681            _lclose(LogVar->FileHandle);
682    
683            for (i = 1 ; i < loopmax ; i++) {
684                    _snprintf_s(filename, sizeof(filename), _TRUNCATE, "%s.%d", LogVar->FullName, i);
685                    if (_access_s(filename, 0) != 0)
686                            break;
687            }
688            if (i >= loopmax) {
689                    // TODO:
690            }
691    
692            // 別ファイルにリネーム。
693            rename(LogVar->FullName, filename);
694    
695            // 再オープン
696            if (ts.LogLockExclusive) {
697                    dwShareMode = FILE_SHARE_READ;
698            }
699            LogVar->FileHandle = (int)CreateFile(LogVar->FullName, GENERIC_WRITE, dwShareMode, NULL,
700                                                 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
701    
702            logfile_unlock();
703    
704    }
705    
706  void LogToFile()  void LogToFile()
707  {  {
708          PCHAR Buf;          PCHAR Buf;
# Line 738  void LogToFile() Line 794  void LogToFile()
794          if (((cv.FilePause & OpLog) !=0) || cv.ProtoFlag) return;          if (((cv.FilePause & OpLog) !=0) || cv.ProtoFlag) return;
795          if (FLogDlg!=NULL)          if (FLogDlg!=NULL)
796                  FLogDlg->RefreshNum();                  FLogDlg->RefreshNum();
797    
798            // ログ・ローテート
799            LogRotate();
800    
801  }  }
802    
803  BOOL CreateLogBuf()  BOOL CreateLogBuf()

Legend:
Removed from v.5141  
changed lines
  Added in v.5162

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