Check availability of pwd.h

This commit is contained in:
Tatsuhiro Tsujikawa 2012-04-07 15:49:22 +09:00
parent c7c26e67c4
commit 840ca5adb6
2 changed files with 7 additions and 4 deletions

View File

@ -317,7 +317,8 @@ AC_CHECK_HEADERS([argz.h \
unistd.h \ unistd.h \
utime.h \ utime.h \
wchar.h \ wchar.h \
ifaddrs.h]) ifaddrs.h \
pwd.h])
# Checks for typedefs, structures, and compiler characteristics. # Checks for typedefs, structures, and compiler characteristics.
AC_HEADER_STDBOOL AC_HEADER_STDBOOL

View File

@ -36,7 +36,9 @@
#include <signal.h> #include <signal.h>
#include <sys/types.h> #include <sys/types.h>
#include <pwd.h> #ifdef HAVE_PWD_H
# include <pwd.h>
#endif // HAVE_PWD_H
#include <cerrno> #include <cerrno>
#include <cassert> #include <cassert>
@ -1026,12 +1028,12 @@ std::string getHomeDir()
} }
} }
} }
#else // !__MINGW32__ #elif HAVE_PWD_H
passwd* pw = getpwuid(geteuid()); passwd* pw = getpwuid(geteuid());
if(pw && pw->pw_dir) { if(pw && pw->pw_dir) {
return pw->pw_dir; return pw->pw_dir;
} }
#endif // !__MINGW32__ #endif // HAVE_PWD_H
return A2STR::NIL; return A2STR::NIL;
} }
} }