LibreOffice Module onlineupdate (master) 1
updatelogging.cxx
Go to the documentation of this file.
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/. */
4
5#if defined(_WIN32)
6#include <windows.h>
7#endif
8
9
10#include <stdio.h>
11#include <string.h>
12#include <stdlib.h>
13#include <stdarg.h>
14
15#include "updatelogging.h"
16
18 : logFP(nullptr)
19 , sourcePath(nullptr)
20{
21}
22
23void UpdateLog::Init(NS_tchar* sourcePathParam,
24 const NS_tchar* fileName,
25 const NS_tchar* alternateFileName,
26 bool append)
27{
28 if (logFP)
29 return;
30
31 sourcePath = sourcePathParam;
32 NS_tchar logFile[MAXPATHLEN];
33 NS_tsnprintf(logFile, sizeof(logFile)/sizeof(logFile[0]),
34 NS_T("%s/%s"), sourcePathParam, fileName);
35
36 if (alternateFileName && NS_taccess(logFile, F_OK))
37 {
38 NS_tsnprintf(logFile, sizeof(logFile)/sizeof(logFile[0]),
39 NS_T("%s/%s"), sourcePathParam, alternateFileName);
40 }
41
42 logFP = NS_tfopen(logFile, append ? NS_T("a") : NS_T("w"));
43}
44
46{
47 if (!logFP)
48 return;
49
50 fclose(logFP);
51 logFP = nullptr;
52}
53
55{
56 if (!logFP)
57 return;
58
59 fflush(logFP);
60}
61
62void UpdateLog::Printf(const char *fmt, ... )
63{
64 if (!logFP)
65 return;
66
67 va_list ap;
68 va_start(ap, fmt);
69 vfprintf(logFP, fmt, ap);
70 fprintf(logFP, "\n");
71 va_end(ap);
72}
73
74void UpdateLog::WarnPrintf(const char *fmt, ... )
75{
76 if (!logFP)
77 return;
78
79 va_list ap;
80 va_start(ap, fmt);
81 fprintf(logFP, "*** Warning: ");
82 vfprintf(logFP, fmt, ap);
83 fprintf(logFP, "***\n");
84 va_end(ap);
85}
void Init(NS_tchar *sourcePath, const NS_tchar *fileName, const NS_tchar *alternateFileName, bool append)
void Printf(const char *fmt,...)
void WarnPrintf(const char *fmt,...)
void Flush()
FILE * logFP
Definition: updatelogging.h:34
void Finish()
NS_tchar * sourcePath
Definition: updatelogging.h:35
#define NS_tfopen
Definition: readstrings.cxx:17
char NS_tchar
Definition: types.hxx:20
#define NS_tsnprintf
#define NS_T(str)
#define NS_taccess
#define MAXPATHLEN
Definition: updatedefines.h:20