home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Linux / Divers / yagirc-0.51.tar.gz / yagirc-0.51.tar / yagirc-0.51 / os.c < prev    next >
C/C++ Source or Header  |  1998-04-23  |  819b  |  44 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4. #include <glib.h>
  5. #include <sys/types.h>
  6.  
  7. #include <unistd.h>
  8. #include <pwd.h>
  9.  
  10. #ifndef HAS_STRUPR
  11. char *strupr(char *str)
  12. {
  13.     char *tmp;
  14.  
  15.     for (tmp = str; *tmp != '\0'; tmp++) *tmp = toupper(*tmp);
  16.  
  17.     return str;
  18. }
  19. #endif
  20.  
  21. char *convhome(char *fname)
  22. {
  23.     struct passwd *pwd;
  24.     char *tmp, *home;
  25.  
  26.     if (*fname != '~') return g_strdup(fname);
  27.  
  28.     home = getenv("HOME");
  29.     if (home == NULL)
  30.     {
  31.         if ((pwd = getpwuid(getuid())) == NULL)
  32.             home = NULL;
  33.         else
  34.             home = pwd->pw_dir;
  35.     }
  36.  
  37.     if (home == NULL || *home == '\0')
  38.         return g_strdup(fname); /* couldn't find home directory.. */
  39.  
  40.     tmp = (char *) g_malloc(strlen(fname)+strlen(home));
  41.     sprintf(tmp, "%s%s", home, fname+1);
  42.     return tmp;
  43. }
  44.