aboutsummaryrefslogtreecommitdiff
path: root/libssh
diff options
context:
space:
mode:
authorAndreas Schneider <mail@cynapses.org>2009-09-09 14:01:20 +0200
committerAndreas Schneider <mail@cynapses.org>2009-09-09 14:01:20 +0200
commit32d52933181eede0a3dd753e39b34a6d1cfa0d18 (patch)
tree14d8344d72197c80eae4abecb1e55e0bb96ed98d /libssh
parente0c969bb41008fc20871045b5d3e218ef5dda551 (diff)
downloadlibssh-32d52933181eede0a3dd753e39b34a6d1cfa0d18.tar.gz
libssh-32d52933181eede0a3dd753e39b34a6d1cfa0d18.tar.xz
libssh-32d52933181eede0a3dd753e39b34a6d1cfa0d18.zip
Add a portable ssh_mkdir function for Windows.
Diffstat (limited to 'libssh')
-rw-r--r--libssh/keyfiles.c2
-rw-r--r--libssh/libssh.map3
-rw-r--r--libssh/misc.c25
3 files changed, 29 insertions, 1 deletions
diff --git a/libssh/keyfiles.c b/libssh/keyfiles.c
index d219dc10..851d5561 100644
--- a/libssh/keyfiles.c
+++ b/libssh/keyfiles.c
@@ -1470,7 +1470,7 @@ int ssh_write_knownhost(SSH_SESSION *session) {
return -1;
}
if (! ssh_file_readaccess_ok(dir)) {
- if (mkdir(dir, 0700) < 0) {
+ if (ssh_mkdir(dir, 0700) < 0) {
ssh_set_error(session, SSH_FATAL,
"Cannot create %s directory.", dir);
SAFE_FREE(dir);
diff --git a/libssh/libssh.map b/libssh/libssh.map
index 359dae95..3e260dfc 100644
--- a/libssh/libssh.map
+++ b/libssh/libssh.map
@@ -104,6 +104,9 @@ SSH_0.3 {
ssh_get_random;
ssh_get_status;
ssh_get_version;
+ ssh_mkdir;
+ ssh_basename;
+ ssh_dirname;
ssh_init;
ssh_is_server_known;
ssh_log;
diff --git a/libssh/misc.c b/libssh/misc.c
index 1359c156..b97b7e02 100644
--- a/libssh/misc.c
+++ b/libssh/misc.c
@@ -27,6 +27,7 @@
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
+#include <sys/stat.h>
#include <sys/types.h>
#include "config.h"
@@ -35,6 +36,7 @@
#define _WIN32_IE 0x0400 //SHGetSpecialFolderPath
#include <shlobj.h>
#include <winsock2.h>
+#include <direct.h>
#else
#include <pwd.h>
#include <arpa/inet.h>
@@ -258,5 +260,28 @@ char *ssh_basename (const char *path) {
return new;
}
+/**
+ * @brief Attempts to create a directory with the given pathname.
+ *
+ * This is the portable version of mkdir, mode is ignored on Windows systems.
+ *
+ * @param pathname The path name to create the directory.
+ *
+ * @param mode The permissions to use.
+ *
+ * @return 0 on success, < 0 on error with errno set.
+ */
+int ssh_mkdir(const char *pathname, mode_t mode) {
+ int r;
+
+#ifdef _WIN32
+ r = _mkdir(pathname);
+#else
+ r = mkdir(pathname, mode);
+#endif
+
+ return r;
+}
+
/** @} */
/* vim: set ts=2 sw=2 et cindent: */