Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #if defined(XP_WIN)
6 #include <windows.h>
7 #endif
10 #include <stdio.h>
11 #include <string.h>
12 #include <stdlib.h>
13 #include <stdarg.h>
15 #include "updatelogging.h"
17 UpdateLog::UpdateLog() : logFP(nullptr)
18 {
19 }
21 void UpdateLog::Init(NS_tchar* sourcePath,
22 const NS_tchar* fileName,
23 const NS_tchar* alternateFileName,
24 bool append)
25 {
26 if (logFP)
27 return;
29 this->sourcePath = sourcePath;
30 NS_tchar logFile[MAXPATHLEN];
31 NS_tsnprintf(logFile, sizeof(logFile)/sizeof(logFile[0]),
32 NS_T("%s/%s"), sourcePath, fileName);
34 if (alternateFileName && NS_taccess(logFile, F_OK)) {
35 NS_tsnprintf(logFile, sizeof(logFile)/sizeof(logFile[0]),
36 NS_T("%s/%s"), sourcePath, alternateFileName);
37 }
39 logFP = NS_tfopen(logFile, append ? NS_T("a") : NS_T("w"));
40 }
42 void UpdateLog::Finish()
43 {
44 if (!logFP)
45 return;
47 fclose(logFP);
48 logFP = nullptr;
49 }
51 void UpdateLog::Flush()
52 {
53 if (!logFP)
54 return;
56 fflush(logFP);
57 }
59 void UpdateLog::Printf(const char *fmt, ... )
60 {
61 if (!logFP)
62 return;
64 va_list ap;
65 va_start(ap, fmt);
66 vfprintf(logFP, fmt, ap);
67 fprintf(logFP, "\n");
68 va_end(ap);
69 }
71 void UpdateLog::WarnPrintf(const char *fmt, ... )
72 {
73 if (!logFP)
74 return;
76 va_list ap;
77 va_start(ap, fmt);
78 fprintf(logFP, "*** Warning: ");
79 vfprintf(logFP, fmt, ap);
80 fprintf(logFP, "***\n");
81 va_end(ap);
82 }