aboutsummaryrefslogtreecommitdiff
path: root/tests/torture.c
diff options
context:
space:
mode:
authorAnderson Toshiyuki Sasaki <ansasaki@redhat.com>2018-11-20 14:01:57 +0100
committerAndreas Schneider <asn@cryptomilk.org>2018-11-28 15:51:06 +0100
commit0dd2b375c770854f73fa64b8e43c741e074de7e6 (patch)
treeabda610bbcec6c88406a96285790fe950a088958 /tests/torture.c
parent77be4ce9056e86f13b06fe15f410d663f5e7b771 (diff)
downloadlibssh-0dd2b375c770854f73fa64b8e43c741e074de7e6.tar.gz
libssh-0dd2b375c770854f73fa64b8e43c741e074de7e6.tar.xz
libssh-0dd2b375c770854f73fa64b8e43c741e074de7e6.zip
tests: Introduce functions to change directories
This introduces torture_get_current_working_dir() and torture_change_dir() to allow changing directories in tests. Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
Diffstat (limited to 'tests/torture.c')
-rw-r--r--tests/torture.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/tests/torture.c b/tests/torture.c
index f7ed775e..88387edb 100644
--- a/tests/torture.c
+++ b/tests/torture.c
@@ -39,11 +39,13 @@
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#elif (defined _WIN32) || (defined _WIN64)
+#include <direct.h>
#include <io.h>
#define read _read
#define open _open
#define write _write
#define close _close
+#define chdir _chdir
#endif
#include "torture.h"
@@ -842,6 +844,28 @@ end:
return new_file;
}
+char *torture_get_current_working_dir(void)
+{
+
+ char *cwd = NULL;
+ char *result = NULL;
+
+ cwd = (char *)malloc(PATH_MAX + 1);
+ if (cwd == NULL) {
+ goto end;
+ }
+
+ result = getcwd(cwd, PATH_MAX);
+
+ if (result == NULL) {
+ SAFE_FREE(cwd);
+ goto end;
+ }
+
+end:
+ return cwd;
+}
+
#else /* _WIN32 */
char *torture_make_temp_dir(const char *template)
@@ -1072,8 +1096,44 @@ end:
return path;
}
+char *torture_get_current_working_dir(void)
+{
+ char *cwd = NULL;
+ char *result = NULL;
+
+ cwd = (char *)malloc(_MAX_PATH + 1);
+ if (cwd == NULL) {
+ goto end;
+ }
+
+ result = _getcwd(cwd, _MAX_PATH);
+
+ if (result == NULL) {
+ SAFE_FREE(cwd);
+ goto end;
+ }
+
+end:
+ return cwd;
+}
+
#endif /* _WIN32 */
+int torture_change_dir(char *path)
+{
+ int rc = 0;
+
+ if (path == NULL) {
+ rc = -1;
+ goto end;
+ }
+
+ rc = chdir(path);
+
+end:
+ return rc;
+}
+
int torture_libssh_verbosity(void){
return verbosity;
}