aboutsummaryrefslogtreecommitdiff
path: root/libssh/options.c
diff options
context:
space:
mode:
authorAndreas Schneider <mail@cynapses.org>2009-04-02 10:18:01 +0000
committerAndreas Schneider <mail@cynapses.org>2009-04-02 10:18:01 +0000
commit8de3dc44ca3dc4285d34925be5a7b4fee8e95408 (patch)
tree3d5f803f4fd54eea41ef32930c6e931045b03cf9 /libssh/options.c
parentab54736b5d41df8588d3754f6b68e2c4c762413f (diff)
downloadlibssh-8de3dc44ca3dc4285d34925be5a7b4fee8e95408.tar.gz
libssh-8de3dc44ca3dc4285d34925be5a7b4fee8e95408.tar.xz
libssh-8de3dc44ca3dc4285d34925be5a7b4fee8e95408.zip
Improve ssh_options_set_username().
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@349 7dcaeef0-15fb-0310-b436-a5af3365683c
Diffstat (limited to 'libssh/options.c')
-rw-r--r--libssh/options.c29
1 files changed, 21 insertions, 8 deletions
diff --git a/libssh/options.c b/libssh/options.c
index e12a235..2bdc589 100644
--- a/libssh/options.c
+++ b/libssh/options.c
@@ -257,15 +257,28 @@ int ssh_options_set_host(SSH_OPTIONS *opt, const char *hostname){
return 0;
}
-/** \brief set username for authentication
- * \bug this should not be set at options time
- * \param opt options structure
- * \param username user name to authenticate
+/**
+ * @brief Set the username for authentication
+ *
+ * @param opt The options structure to use.
+ *
+ * @param username The username to authenticate.
+ *
+ * @return 0 on success, -1 on error.
+ *
+ * @bug this should not be set at options time
*/
-void ssh_options_set_username(SSH_OPTIONS *opt, const char *username){
- if(opt->username)
- free(opt->username);
- opt->username=strdup(username);
+int ssh_options_set_username(SSH_OPTIONS *opt, const char *username) {
+ if (opt->username) {
+ SAFE_FREE(opt->username);
+ }
+
+ opt->username = strdup(username);
+ if (opt->username == NULL) {
+ return -1;
+ }
+
+ return 0;
}
/** If you wish to open the socket yourself for a reason