FreeRDP
utils/helpers.c
1 
21 #include <freerdp/utils/helpers.h>
22 
23 #include <winpr/path.h>
24 #include <freerdp/version.h>
25 #include <freerdp/build-config.h>
26 
27 #if defined(WITH_RESOURCE_VERSIONING)
28 #define STR(x) #x
29 #endif
30 
31 char* freerdp_GetConfigFilePath(BOOL system, const char* filename)
32 {
33  eKnownPathTypes id = system ? KNOWN_PATH_SYSTEM_CONFIG_HOME : KNOWN_PATH_XDG_CONFIG_HOME;
34 
35 #if defined(FREERDP_USE_VENDOR_PRODUCT_CONFIG_DIR)
36  char* vendor = GetKnownSubPath(id, FREERDP_VENDOR_STRING);
37 #else
38  char* vendor = GetKnownPath(id);
39 #endif
40  if (!vendor)
41  return NULL;
42 
43 #if defined(WITH_RESOURCE_VERSIONING)
44  char* verstr = FREERDP_PRODUCT_STRING STR(FREERDP_VERSION_MAJOR);
45 #else
46  char* verstr = FREERDP_PRODUCT_STRING;
47 #endif
48 
49  char* base = GetCombinedPath(vendor, verstr);
50  free(vendor);
51 
52  if (!base)
53  return NULL;
54 
55  if (!filename)
56  return base;
57 
58  char* path = GetCombinedPath(base, filename);
59  free(base);
60  return path;
61 }