diff options
author | Andreas Schneider <mail@cynapses.org> | 2009-04-02 12:00:45 +0000 |
---|---|---|
committer | Andreas Schneider <mail@cynapses.org> | 2009-04-02 12:00:45 +0000 |
commit | 9ea6ea581d655d81d40efc7c678e8e1f036d533d (patch) | |
tree | d8aa035c0421b8f44964ab925f3176980d336e12 /libssh/options.c | |
parent | 4373fc64e345a994d2a207ddc7f1a11859ec7176 (diff) | |
download | libssh-9ea6ea581d655d81d40efc7c678e8e1f036d533d.tar.gz libssh-9ea6ea581d655d81d40efc7c678e8e1f036d533d.tar.xz libssh-9ea6ea581d655d81d40efc7c678e8e1f036d533d.zip |
Improve ssh_options_set_ssh_dir().
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@354 7dcaeef0-15fb-0310-b436-a5af3365683c
Diffstat (limited to 'libssh/options.c')
-rw-r--r-- | libssh/options.c | 39 |
1 files changed, 28 insertions, 11 deletions
diff --git a/libssh/options.c b/libssh/options.c index 77f44a7f..8c318883 100644 --- a/libssh/options.c +++ b/libssh/options.c @@ -355,18 +355,35 @@ int ssh_options_set_bind(SSH_OPTIONS *opt, const char *bindaddr, int port) { return 0; } -/** the ssh directory is used for files like known_hosts and - * identity (public and private keys)\n - * \brief set the ssh directory - * \param opt options structure - * \param dir directory. It may include "%s" which will be replaced by - * the user home directory - * \see ssh_options_set_user_home_dir() +/** + * @brief Set the ssh directory. + * + * The ssh directory is used for files like known_hosts and identity (public + * and private keys) + * + * @param opt The options structure to use. + * + * @param dir The directory to set. It may include "%s" which will be + * replaced by the user home directory. + * + * @return 0 on success, < 0 on error. + * + * @see ssh_options_set_user_home_dir() */ -void ssh_options_set_ssh_dir(SSH_OPTIONS *opt, const char *dir){ - char buffer[1024]; - snprintf(buffer,1024,dir,ssh_get_user_home_dir()); - opt->ssh_dir=strdup(buffer); +int ssh_options_set_ssh_dir(SSH_OPTIONS *opt, const char *dir) { + char buffer[1024] = {0}; + + if (opt == NULL || dir == NULL) { + return -1; + } + + snprintf(buffer, 1024, dir, ssh_get_user_home_dir()); + opt->ssh_dir = strdup(buffer); + if (opt->ssh_dir == NULL) { + return -1; + } + + return 0; } /** the known hosts file is used to certify remote hosts are genuine. |