/src/FreeRDP/winpr/libwinpr/utils/wlog/Message.c
Line  | Count  | Source (jump to first uncovered line)  | 
1  |  | /**  | 
2  |  |  * WinPR: Windows Portable Runtime  | 
3  |  |  * WinPR Logger  | 
4  |  |  *  | 
5  |  |  * Copyright 2013 Marc-Andre Moreau <marcandre.moreau@gmail.com>  | 
6  |  |  *  | 
7  |  |  * Licensed under the Apache License, Version 2.0 (the "License");  | 
8  |  |  * you may not use this file except in compliance with the License.  | 
9  |  |  * You may obtain a copy of the License at  | 
10  |  |  *  | 
11  |  |  *     http://www.apache.org/licenses/LICENSE-2.0  | 
12  |  |  *  | 
13  |  |  * Unless required by applicable law or agreed to in writing, software  | 
14  |  |  * distributed under the License is distributed on an "AS IS" BASIS,  | 
15  |  |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  | 
16  |  |  * See the License for the specific language governing permissions and  | 
17  |  |  * limitations under the License.  | 
18  |  |  */  | 
19  |  |  | 
20  |  | #include <winpr/config.h>  | 
21  |  |  | 
22  |  | #include <winpr/crt.h>  | 
23  |  | #include <winpr/path.h>  | 
24  |  | #include <winpr/file.h>  | 
25  |  |  | 
26  |  | #include "wlog.h"  | 
27  |  |  | 
28  |  | #include "Message.h"  | 
29  |  |  | 
30  |  | char* WLog_Message_GetOutputFileName(int id, const char* ext)  | 
31  | 0  | { | 
32  | 0  |   DWORD ProcessId = 0;  | 
33  | 0  |   char* FilePath = NULL;  | 
34  | 0  |   char* FileName = NULL;  | 
35  | 0  |   char* FullFileName = NULL;  | 
36  |  | 
  | 
37  | 0  |   if (!(FileName = (char*)malloc(256)))  | 
38  | 0  |     return NULL;  | 
39  |  |  | 
40  | 0  |   FilePath = GetKnownSubPath(KNOWN_PATH_TEMP, "wlog");  | 
41  |  | 
  | 
42  | 0  |   if (!winpr_PathFileExists(FilePath))  | 
43  | 0  |   { | 
44  | 0  |     if (!winpr_PathMakePath(FilePath, NULL))  | 
45  | 0  |     { | 
46  | 0  |       free(FileName);  | 
47  | 0  |       free(FilePath);  | 
48  | 0  |       return NULL;  | 
49  | 0  |     }  | 
50  | 0  |   }  | 
51  |  |  | 
52  | 0  |   ProcessId = GetCurrentProcessId();  | 
53  | 0  |   if (id >= 0)  | 
54  | 0  |     (void)sprintf_s(FileName, 256, "%" PRIu32 "-%d.%s", ProcessId, id, ext);  | 
55  | 0  |   else  | 
56  | 0  |     (void)sprintf_s(FileName, 256, "%" PRIu32 ".%s", ProcessId, ext);  | 
57  |  | 
  | 
58  | 0  |   FullFileName = GetCombinedPath(FilePath, FileName);  | 
59  |  | 
  | 
60  | 0  |   free(FileName);  | 
61  | 0  |   free(FilePath);  | 
62  |  | 
  | 
63  | 0  |   return FullFileName;  | 
64  | 0  | }  |