librnr/path.c
char *NewExpandTilde(const char *sTildeExpr)
{
  char          *sUser;
  struct passwd *pPassEntry;
  uid_t          uid;
  char          *sExpanded = NULL;

  // expression must start with a tilde
  if( (sTildeExpr == NULL) || (*sTildeExpr != '~') )
  {
    return NULL;
  }

  // user name
  sUser = (char *)sTildeExpr + 1;

  // expand this user's home
  if( (*sUser == 0) || (*sUser == DIR_SEP_CHAR) || (*sUser == PATH_SEP_CHAR) )
  {
    if( (sExpanded = getenv("HOME")) == NULL )
    {
      uid = getuid();
      if( (pPassEntry = getpwuid(uid)) != NULL )
      {
        sExpanded = pPassEntry->pw_dir;
      }
    }
  }
  
  // expand other user's home
  else
  {
    if( (pPassEntry = getpwnam(sUser)) != NULL )
    {
      sExpanded = pPassEntry->pw_dir;
    }
  }

  if( sExpanded != NULL )
  {
    return new_strdup(sExpanded);
  }
  else
  {
    return NULL;
  }
}
/*!
 * \brief Expand tilde expression.
 *
 * \param sTildeExpr    '~' [user]
 *
 * \return 
 *  Return allocated expanded tilde expression path on success.\n
 *  If the expression has invalid syntax or the user does not exist, then
 *  NULL is returned.
 */
\brief Expand tilde expression.
\param sTildeExpr    '~' [user]

\return
Return allocated expanded tilde expression path on success.\n
If the expression has invalid syntax or the user does not exist, then
NULL is returned.
\ brief Expand tilde expression . \ param sTildeExpr ' ~ ' [ user ] \ return Return allocated expanded tilde expression path on success . \ n If the expression has invalid syntax or the user does not exist then NULL is returned .
char *NewExpandTilde(const char *sTildeExpr)
{
  char          *sUser;
  struct passwd *pPassEntry;
  uid_t          uid;
  char          *sExpanded = NULL;
  if( (sTildeExpr == NULL) || (*sTildeExpr != '~') )
  {
    return NULL;
  }
  sUser = (char *)sTildeExpr + 1;
  if( (*sUser == 0) || (*sUser == DIR_SEP_CHAR) || (*sUser == PATH_SEP_CHAR) )
  {
    if( (sExpanded = getenv("HOME")) == NULL )
    {
      uid = getuid();
      if( (pPassEntry = getpwuid(uid)) != NULL )
      {
        sExpanded = pPassEntry->pw_dir;
      }
    }
  }
  else
  {
    if( (pPassEntry = getpwnam(sUser)) != NULL )
    {
      sExpanded = pPassEntry->pw_dir;
    }
  }
  if( sExpanded != NULL )
  {
    return new_strdup(sExpanded);
  }
  else
  {
    return NULL;
  }
}
char * NewExpandTilde ( const char * sTildeExpr ) { char * sUser ; struct passwd * pPassEntry ; uid_t uid ; char * sExpanded = NULL ; if ( ( sTildeExpr == NULL ) || ( * sTildeExpr != ' ' ) ) { return NULL ; } sUser = ( char * ) sTildeExpr + 1 ; if ( ( * sUser == 0 ) || ( * sUser == DIR_SEP_CHAR ) || ( * sUser == PATH_SEP_CHAR ) ) { if ( ( sExpanded = getenv ( " " ) ) == NULL ) { uid = getuid ( ) ; if ( ( pPassEntry = getpwuid ( uid ) ) != NULL ) { sExpanded = pPassEntry -> pw_dir ; } } } else { if ( ( pPassEntry = getpwnam ( sUser ) ) != NULL ) { sExpanded = pPassEntry -> pw_dir ; } } if ( sExpanded != NULL ) { return new_strdup ( sExpanded ) ; } else { return NULL ; } }
\brief Expand tilde expression.
\ brief Expand tilde expression .
// expression must start with a tilde // user name // expand this user's home // expand other user's home