mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-09 18:04:25 +09:00
Cleanup misc functions.
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@453 7dcaeef0-15fb-0310-b436-a5af3365683c
This commit is contained in:
@@ -67,49 +67,54 @@
|
|||||||
/** \addtogroup ssh_misc
|
/** \addtogroup ssh_misc
|
||||||
* @{ */
|
* @{ */
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifdef _WIN32
|
||||||
|
|
||||||
char *ssh_get_user_home_dir(void) {
|
char *ssh_get_user_home_dir(void) {
|
||||||
static char szPath[PATH_MAX] = {0};
|
static char szPath[MAX_PATH] = {0};
|
||||||
struct passwd *pwd = NULL;
|
|
||||||
|
|
||||||
pwd = getpwuid(getuid());
|
|
||||||
if (pwd == NULL) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
snprintf(szPath, PATH_MAX - 1, "%s", pwd->pw_dir);
|
|
||||||
|
|
||||||
|
if (SHGetSpecialFolderPathA(NULL, szPath, CSIDL_PROFILE, TRUE)) {
|
||||||
return szPath;
|
return szPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
#else /* _WIN32 */
|
#else /* _WIN32 */
|
||||||
|
|
||||||
char *ssh_get_user_home_dir(void) {
|
char *ssh_get_user_home_dir(void) {
|
||||||
static char szPath[MAX_PATH];
|
static char szPath[PATH_MAX] = {0};
|
||||||
if (SHGetSpecialFolderPathA(NULL, szPath, CSIDL_PROFILE, TRUE))
|
struct passwd *pwd = NULL;
|
||||||
return szPath;
|
|
||||||
else
|
pwd = getpwuid(getuid());
|
||||||
return NULL;
|
if (pwd == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
snprintf(szPath, PATH_MAX - 1, "%s", pwd->pw_dir);
|
||||||
|
|
||||||
|
return szPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* we have read access on file */
|
/* we have read access on file */
|
||||||
int ssh_file_readaccess_ok(const char *file){
|
int ssh_file_readaccess_ok(const char *file) {
|
||||||
if(!access(file,R_OK))
|
if (access(file, R_OK) < 0) {
|
||||||
return 1;
|
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 ntohll(u64 a){
|
u64 ntohll(u64 a) {
|
||||||
#ifdef WORDS_BIGENDIAN
|
#ifdef WORDS_BIGENDIAN
|
||||||
return a;
|
return a;
|
||||||
#else
|
#else
|
||||||
u32 low=a & 0xffffffff;
|
u32 low = a & 0xffffffff;
|
||||||
u32 high = a >> 32 ;
|
u32 high = a >> 32 ;
|
||||||
low=ntohl(low);
|
low = ntohl(low);
|
||||||
high=ntohl(high);
|
high = ntohl(high);
|
||||||
return (( ((u64)low) << 32) | ( high));
|
|
||||||
|
return ((((u64) low) << 32) | ( high));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user