src/util/texpand.c File Reference

#include "util.h"
Include dependency graph for texpand.c:

Go to the source code of this file.

Functions

char * util_tilde_expand (char const *fname)

Function Documentation

char* util_tilde_expand ( char const *  fname  ) 

Definition at line 16 of file texpand.c.

00017 {
00018 #if HAVE_PWD_H
00019     struct passwd *userRecord;
00020     char username[256], *filename, *dir;
00021     register int i, j;
00022 
00023     filename = ALLOC(char, strlen(fname) + 256);
00024 
00025     /* Clear the return string */
00026     i = 0;
00027     filename[0] = '\0';
00028 
00029     /* Tilde? */
00030     if (fname[0] == '~') {
00031         j = 0;
00032         i = 1;
00033         while ((fname[i] != '\0') && (fname[i] != '/')) {
00034             username[j++] = fname[i++];
00035         }
00036         username[j] = '\0';
00037         dir = (char *)0;
00038         if (username[0] == '\0') {
00039             /* ~/ resolves to home directory of current user */
00040             userRecord = getpwuid(getuid());
00041             if (userRecord) dir = userRecord->pw_dir;
00042         } else {
00043             /* Special check for ~octtools */
00044             if (!strcmp(username,"octtools"))
00045                 dir = getenv("OCTTOOLS");
00046             /* ~user/ resolves to home directory of 'user' */
00047             if (!dir) {
00048                 userRecord = getpwnam(username);
00049                 if (userRecord) dir = userRecord->pw_dir;
00050             }
00051         }
00052         if (dir) (void) strcat(filename, dir);
00053         else i = 0;     /* leave fname as-is */
00054     } /* if tilde */
00055 
00056     /* Concantenate remaining portion of file name */
00057     (void) strcat(filename, fname + i);
00058     return filename;
00059 #else
00060     return util_strsav(fname);
00061 #endif
00062 }


Generated on Tue Jan 12 13:57:29 2010 for glu-2.2 by  doxygen 1.6.1