#include <winpr/path.h>
+#if defined(__IOS__)
+#include "shell_ios.h"
+#endif
+
#if defined(WIN32)
#include <Shlobj.h>
#else
{
DWORD length;
char* env = NULL;
-
length = GetEnvironmentVariableA(lpName, NULL, 0);
if (length > 0)
{
env = malloc(length + 1);
+
if (!env)
return NULL;
+
GetEnvironmentVariableA(lpName, env, length + 1);
env[length] = '\0';
}
static char* GetPath_HOME(void)
{
char* path = NULL;
-
#ifdef _WIN32
path = GetEnvAlloc("UserProfile");
+#elif defined(__IOS__)
+ path = ios_get_home();
#else
path = GetEnvAlloc("HOME");
#endif
-
return path;
}
static char* GetPath_TEMP(void)
{
char* path = NULL;
-
#ifdef _WIN32
path = GetEnvAlloc("TEMP");
+#elif defined(__IOS__)
+ path = ios_get_temp();
#else
path = GetEnvAlloc("TMPDIR");
if (!path)
path = _strdup("/tmp");
-#endif
+#endif
return path;
}
static char* GetPath_XDG_DATA_HOME(void)
{
char* path = NULL;
-
#if defined(WIN32)
path = GetPath_XDG_CONFIG_HOME();
#else
* $XDG_DATA_HOME defines the base directory relative to which user specific data files should be stored.
* If $XDG_DATA_HOME is either not set or empty, a default equal to $HOME/.local/share should be used.
*/
-
path = GetEnvAlloc("XDG_DATA_HOME");
if (path)
return path;
home = GetPath_HOME();
+
if (!home)
return NULL;
path = (char*) malloc(strlen(home) + strlen("/.local/share") + 1);
+
if (!path)
{
free(home);
return NULL;
}
- sprintf(path, "%s%s", home, "/.local/share");
+ sprintf(path, "%s%s", home, "/.local/share");
free(home);
#endif
-
return path;
}
static char* GetPath_XDG_CONFIG_HOME(void)
{
char* path = NULL;
-
#if defined(WIN32) && !defined(_UWP)
path = calloc(MAX_PATH, sizeof(char));
+
if (!path)
return NULL;
free(path);
return NULL;
}
+
+#elif defined(__IOS__)
+ path = GetCombinedPath(GetPath_HOME(), ".freerdp");
#else
char* home = NULL;
/**
* $XDG_CONFIG_HOME defines the base directory relative to which user specific configuration files should be stored.
* If $XDG_CONFIG_HOME is either not set or empty, a default equal to $HOME/.config should be used.
*/
-
path = GetEnvAlloc("XDG_CONFIG_HOME");
if (path)
return NULL;
path = (char*) malloc(strlen(home) + strlen("/.config") + 1);
+
if (!path)
{
free(home);
return NULL;
}
- sprintf(path, "%s%s", home, "/.config");
+ sprintf(path, "%s%s", home, "/.config");
free(home);
#endif
-
return path;
}
{
char* path = NULL;
char* home = NULL;
-
#if defined(WIN32)
home = GetPath_XDG_RUNTIME_DIR();
+
if (home)
{
path = GetCombinedPath(home, "cache");
+
if (!PathFileExistsA(path))
if (!CreateDirectoryA(path, NULL))
path = NULL;
}
+
free(home);
#else
/**
* $XDG_CACHE_HOME defines the base directory relative to which user specific non-essential data files should be stored.
* If $XDG_CACHE_HOME is either not set or empty, a default equal to $HOME/.cache should be used.
*/
-
path = GetEnvAlloc("XDG_CACHE_HOME");
if (path)
return path;
home = GetPath_HOME();
+
if (!home)
return NULL;
path = (char*) malloc(strlen(home) + strlen("/.cache") + 1);
+
if (!path)
{
free(home);
return NULL;
}
- sprintf(path, "%s%s", home, "/.cache");
+ sprintf(path, "%s%s", home, "/.cache");
free(home);
#endif
-
return path;
}
char* GetPath_XDG_RUNTIME_DIR(void)
{
char* path = NULL;
-
#if defined(WIN32) && !defined(_UWP)
path = calloc(MAX_PATH, sizeof(char));
+
if (!path)
return NULL;
- if (FAILED(SHGetFolderPathA(0, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, path)))
+ if (FAILED(SHGetFolderPathA(0, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT,
+ path)))
{
free(path);
return NULL;
}
+
#else
/**
* There is a single base directory relative to which user-specific runtime files and other file objects should be placed.
* print a warning message. Applications should use this directory for communication and synchronization purposes and
* should not place larger files in it, since it might reside in runtime memory and cannot necessarily be swapped out to disk.
*/
-
path = GetEnvAlloc("XDG_RUNTIME_DIR");
#endif
return path;
path = GetPath_TEMP();
-
return path;
}
case KNOWN_PATH_TEMP:
path = GetPath_TEMP();
-
break;
case KNOWN_PATH_XDG_DATA_HOME:
{
char* subPath;
char* knownPath;
-
knownPath = GetKnownPath(id);
+
if (!knownPath)
return NULL;
- subPath = GetCombinedPath(knownPath, path);
+ subPath = GetCombinedPath(knownPath, path);
free(knownPath);
-
return subPath;
}
{
char* env = NULL;
DWORD nSize;
-
nSize = GetEnvironmentVariableA(name, NULL, 0);
if (nSize)
{
env = (LPSTR) malloc(nSize);
+
if (!env)
return NULL;
+
nSize = GetEnvironmentVariableA(name, env, nSize);
}
{
char* env;
char* subpath;
-
env = GetEnvironmentPath(name);
if (!env)
return NULL;
subpath = GetCombinedPath(env, path);
-
free(env);
-
return subpath;
}
if (basePath)
basePathLength = (int) strlen(basePath);
+
if (subPath)
subPathLength = (int) strlen(subPath);
length = basePathLength + subPathLength + 1;
path = (char*) malloc(length + 1);
+
if (!path)
return NULL;
if (basePath)
CopyMemory(path, basePath, basePathLength);
+
path[basePathLength] = '\0';
if (FAILED(PathCchConvertStyleA(path, basePathLength, PATH_STYLE_NATIVE)))
return path;
subPathCpy = _strdup(subPath);
+
if (!subPathCpy)
{
free(path);
return NULL;
}
+
if (FAILED(PathCchConvertStyleA(subPathCpy, subPathLength, PATH_STYLE_NATIVE)))
{
free(path);
}
status = NativePathCchAppendA(path, length + 1, subPathCpy);
-
free(subPathCpy);
if (FAILED(status))
for (p = dup; p;)
{
if ((p = strchr(p + 1, delim)))
- *p = '\0';
+ * p = '\0';
if (mkdir(dup, 0777) != 0)
if (errno != EEXIST)
break;
+
if (p)
*p = delim;
}
--- /dev/null
+/**
+ * WinPR: Windows Portable Runtime
+ * Path Functions
+ *
+ * Copyright 2016 Armin Novak <armin.novak@thincast.om>
+ * Copyright 2016 Thincast Technologies GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#import <Foundation/Foundation.h>
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "shell_ios.h"
+
+char* ios_get_home(void)
+{
+ NSString* home_path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
+ NSUserDomainMask, YES) lastObject];
+ return strdup([home_path UTF8String]);
+}
+
+char* ios_get_temp(void)
+{
+ NSString* tmp_path = [NSTemporaryDirectory() stringByAppendingPathComponent:@"freerdp"];
+ return strdup([tmp_path UTF8String]);
+}