diff options
author | Andreas Schneider <mail@cynapses.org> | 2009-09-09 13:42:00 +0200 |
---|---|---|
committer | Andreas Schneider <mail@cynapses.org> | 2009-09-09 13:42:00 +0200 |
commit | 97b6036cbf3e444384a8e9b7f082e22d9ea64fe1 (patch) | |
tree | f0d5f611d728dcc73d6b81153800003137ab1caa /libssh | |
parent | df4f7ed5b8ec4619c3435b9b3dc8efc6210f4447 (diff) | |
download | libssh-97b6036cbf3e444384a8e9b7f082e22d9ea64fe1.tar.gz libssh-97b6036cbf3e444384a8e9b7f082e22d9ea64fe1.tar.xz libssh-97b6036cbf3e444384a8e9b7f082e22d9ea64fe1.zip |
Add a portable ssh_mkdir function for Windows.
Diffstat (limited to 'libssh')
-rw-r--r-- | libssh/keyfiles.c | 2 | ||||
-rw-r--r-- | libssh/misc.c | 25 |
2 files changed, 26 insertions, 1 deletions
diff --git a/libssh/keyfiles.c b/libssh/keyfiles.c index 55b2c778..0e73fcba 100644 --- a/libssh/keyfiles.c +++ b/libssh/keyfiles.c @@ -1469,7 +1469,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/misc.c b/libssh/misc.c index 5fbd28e2..1f977eb4 100644 --- a/libssh/misc.c +++ b/libssh/misc.c @@ -26,6 +26,7 @@ #include <stdio.h> #include <string.h> #include <stdlib.h> +#include <sys/stat.h> #include <sys/types.h> #include "config.h" @@ -34,6 +35,7 @@ #define _WIN32_IE 0x0400 //SHGetSpecialFolderPath #include <winsock2.h> // Must be the first to include #include <shlobj.h> +#include <direct.h> #else #include <pwd.h> #include <arpa/inet.h> @@ -347,5 +349,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: */ |