diff options
author | Andreas Schneider <mail@cynapses.org> | 2009-04-10 09:06:27 +0000 |
---|---|---|
committer | Andreas Schneider <mail@cynapses.org> | 2009-04-10 09:06:27 +0000 |
commit | e4624d6ed7f6506c0d93ca22fa04b10fc4f16894 (patch) | |
tree | 5c5fe0b8490800f1035bff7069e9486a4b804a14 /libssh/misc.c | |
parent | c841e984baeb8d42d3d26511b5d049c9ff4c7313 (diff) | |
download | libssh-e4624d6ed7f6506c0d93ca22fa04b10fc4f16894.tar.gz libssh-e4624d6ed7f6506c0d93ca22fa04b10fc4f16894.tar.xz libssh-e4624d6ed7f6506c0d93ca22fa04b10fc4f16894.zip |
Cleanup misc functions.
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@453 7dcaeef0-15fb-0310-b436-a5af3365683c
Diffstat (limited to 'libssh/misc.c')
-rw-r--r-- | libssh/misc.c | 57 |
1 files changed, 31 insertions, 26 deletions
diff --git a/libssh/misc.c b/libssh/misc.c index 3f404fd..095614a 100644 --- a/libssh/misc.c +++ b/libssh/misc.c @@ -67,49 +67,54 @@ /** \addtogroup ssh_misc * @{ */ -#ifndef _WIN32 -char *ssh_get_user_home_dir(void) { - static char szPath[PATH_MAX] = {0}; - struct passwd *pwd = NULL; - - pwd = getpwuid(getuid()); - if (pwd == NULL) { - return NULL; - } +#ifdef _WIN32 - snprintf(szPath, PATH_MAX - 1, "%s", pwd->pw_dir); +char *ssh_get_user_home_dir(void) { + static char szPath[MAX_PATH] = {0}; + if (SHGetSpecialFolderPathA(NULL, szPath, CSIDL_PROFILE, TRUE)) { return szPath; -} + } + return NULL; +} #else /* _WIN32 */ char *ssh_get_user_home_dir(void) { - static char szPath[MAX_PATH]; - if (SHGetSpecialFolderPathA(NULL, szPath, CSIDL_PROFILE, TRUE)) - return szPath; - else - return NULL; + static char szPath[PATH_MAX] = {0}; + struct passwd *pwd = NULL; + + pwd = getpwuid(getuid()); + if (pwd == NULL) { + return NULL; + } + + snprintf(szPath, PATH_MAX - 1, "%s", pwd->pw_dir); + + return szPath; } #endif /* we have read access on file */ -int ssh_file_readaccess_ok(const char *file){ - if(!access(file,R_OK)) - return 1; +int ssh_file_readaccess_ok(const char *file) { + if (access(file, R_OK) < 0) { return 0; + } + + return 1; } -u64 ntohll(u64 a){ +u64 ntohll(u64 a) { #ifdef WORDS_BIGENDIAN - return a; + return a; #else - u32 low=a & 0xffffffff; - u32 high = a >> 32 ; - low=ntohl(low); - high=ntohl(high); - return (( ((u64)low) << 32) | ( high)); + u32 low = a & 0xffffffff; + u32 high = a >> 32 ; + low = ntohl(low); + high = ntohl(high); + + return ((((u64) low) << 32) | ( high)); #endif } |