Logo Search packages:      
Sourcecode: freetds version File versions

char* tds_get_homedir ( void   ) 

Get user home directory

Returns:
home directory or NULL if error. Should be freed with free

Definition at line 220 of file threadsafe.c.

References tds_get_homedir().

Referenced by tds_get_homedir().

{
/* if is available getpwuid_r use it */
#if defined(HAVE_GETUID) && defined(HAVE_GETPWUID_R)
      struct passwd *pw, bpw;
      char buf[1024];

#ifdef HAVE_FUNC_GETPWUID_R_5
      if (getpwuid_r(getuid(), &bpw, buf, sizeof(buf), &pw))
            return NULL;
#else /* !HAVE_FUNC_GETPWUID_R_5 */
#ifdef HAVE_FUNC_GETPWUID_R_4_PW
      if (!(pw = getpwuid_r(getuid(), &bpw, buf, sizeof(buf))))
            return NULL;
#else /* !HAVE_FUNC_GETPWUID_R_4_PW */
      if (getpwuid_r(getuid(), &bpw, buf, sizeof(buf)))
            return NULL;
      pw = &bpw;
#endif /* HAVE_FUNC_GETPWUID_R_4_PW */
#endif /* HAVE_FUNC_GETPWUID_R_5 */
      return strdup(pw->pw_dir);
#else
/* if getpwuid is available use it for no reentrant (getpwuid is not reentrant) */
#if defined(HAVE_GETUID) && defined(HAVE_GETPWUID) && !defined(_REENTRANT)
      struct passwd *pw;

      pw = getpwuid(getuid());
      if (!pw)
            return NULL;
      return strdup(pw->pw_dir);
#else
      char *home;

      home = getenv("HOME");
      if (!home || !home[0])
            return NULL;
      return strdup(home);
#endif
#endif
}


Generated by  Doxygen 1.6.0   Back to index