aboutsummaryrefslogtreecommitdiff
path: root/src/helper
diff options
context:
space:
mode:
authorSpencer Oliver <spen@spen-soft.co.uk>2013-03-27 16:28:31 +0000
committerFreddie Chopin <freddie.chopin@gmail.com>2013-04-21 07:28:32 +0000
commitff1108ad383c6c36095a36fc69fd3d19d6995e0f (patch)
tree85a548e3bea45d7d5cd7d44dc874ef155f8ad09e /src/helper
parentd7646942f2fbbbb37af2effb3e7fdeb03c3fe6be (diff)
downloadriscv-openocd-ff1108ad383c6c36095a36fc69fd3d19d6995e0f.zip
riscv-openocd-ff1108ad383c6c36095a36fc69fd3d19d6995e0f.tar.gz
riscv-openocd-ff1108ad383c6c36095a36fc69fd3d19d6995e0f.tar.bz2
telnet: add telnet history support
adapted from Yoshinori Sato's patch: https://github.com/ysat0/openocd/commit/2f07f4600a0da8206612d78c159bbe1171aa41c2 Change-Id: I084b86d316b0aa6e9593f007c024961dbda805e9 Signed-off-by: Spencer Oliver <spen@spen-soft.co.uk> Reviewed-on: http://openocd.zylin.com/1310 Tested-by: jenkins Reviewed-by: Freddie Chopin <freddie.chopin@gmail.com>
Diffstat (limited to 'src/helper')
-rw-r--r--src/helper/configuration.c44
-rw-r--r--src/helper/configuration.h1
2 files changed, 45 insertions, 0 deletions
diff --git a/src/helper/configuration.c b/src/helper/configuration.c
index 49c1c08..bfb73fd 100644
--- a/src/helper/configuration.c
+++ b/src/helper/configuration.c
@@ -128,3 +128,47 @@ int parse_config_file(struct command_context *cmd_ctx)
return ERROR_OK;
}
+
+#ifndef _WIN32
+#include <pwd.h>
+#endif
+
+char *get_home_dir(const char *append_path)
+{
+ char *home = getenv("HOME");
+
+ if (home == NULL) {
+
+#ifdef _WIN32
+ home = getenv("USERPROFILE");
+
+ if (home == NULL) {
+
+ char homepath[MAX_PATH];
+ char *drive = getenv("HOMEDRIVE");
+ char *path = getenv("HOMEPATH");
+ if (drive && path) {
+ snprintf(homepath, MAX_PATH, "%s/%s", drive, path);
+ home = homepath;
+ }
+ }
+#else
+ struct passwd *pwd = getpwuid(getuid());
+ if (pwd)
+ home = pwd->pw_dir;
+
+#endif
+ }
+
+ if (home == NULL)
+ return home;
+
+ char *home_path;
+
+ if (append_path)
+ home_path = alloc_printf("%s/%s", home, append_path);
+ else
+ home_path = alloc_printf("%s", home);
+
+ return home_path;
+}
diff --git a/src/helper/configuration.h b/src/helper/configuration.h
index b329da7..749f007 100644
--- a/src/helper/configuration.h
+++ b/src/helper/configuration.h
@@ -40,5 +40,6 @@ int configuration_output_handler(struct command_context *cmd_ctx,
FILE *open_file_from_path(const char *file, const char *mode);
char *find_file(const char *name);
+char *get_home_dir(const char *append_path);
#endif /* CONFIGURATION_H */