FreeRDP
Message.c
1 
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 {
32  DWORD ProcessId = 0;
33  char* FilePath = NULL;
34  char* FileName = NULL;
35  char* FullFileName = NULL;
36 
37  if (!(FileName = (char*)malloc(256)))
38  return NULL;
39 
40  FilePath = GetKnownSubPath(KNOWN_PATH_TEMP, "wlog");
41 
42  if (!winpr_PathFileExists(FilePath))
43  {
44  if (!winpr_PathMakePath(FilePath, NULL))
45  {
46  free(FileName);
47  free(FilePath);
48  return NULL;
49  }
50  }
51 
52  ProcessId = GetCurrentProcessId();
53  if (id >= 0)
54  (void)sprintf_s(FileName, 256, "%" PRIu32 "-%d.%s", ProcessId, id, ext);
55  else
56  (void)sprintf_s(FileName, 256, "%" PRIu32 ".%s", ProcessId, ext);
57 
58  FullFileName = GetCombinedPath(FilePath, FileName);
59 
60  free(FileName);
61  free(FilePath);
62 
63  return FullFileName;
64 }