1
#if !defined(lint) && !defined(DOS)
2
static char rcsid[] = "$Id: fnexpand.c 200 2006-10-25 19:01:21Z hubert@u.washington.edu $";
6
* ========================================================================
7
* Copyright 2006 University of Washington
9
* Licensed under the Apache License, Version 2.0 (the "License");
10
* you may not use this file except in compliance with the License.
11
* You may obtain a copy of the License at
13
* http://www.apache.org/licenses/LICENSE-2.0
15
* ========================================================================
20
#include "../charconv/filesys.h"
27
/*----------------------------------------------------------------------
28
Expand the ~ in a file ala the csh (as home directory)
30
Args: buf -- The filename to expand (nothing happens unless begins with ~)
31
len -- The length of the buffer passed in (expansion is in place)
33
Result: Expanded string is returned using same storage as passed in.
34
If expansion fails, NULL is returned
37
fnexpand(char *buf, int len)
40
/* We used to use ps_global->home_dir, now we have to build it */
41
if(*buf == '~' && *(buf+1) == '\\'){
42
char temp_path[_MAX_PATH], home_buf[_MAX_PATH], *temp_home_str;
44
if(getenv("HOME") != NULL)
45
temp_home_str = getenv("HOME");
47
/* should eventually strip this out of get_user_info */
50
if((p = (char *) getenv("HOMEDRIVE"))
51
&& (q = (char *) getenv("HOMEPATH")))
52
snprintf(home_buf, sizeof(home_buf), "%s%s", p, q);
54
snprintf(home_buf, sizeof(home_buf), "%c:\\", '@' + _getdrive());
56
temp_home_str = home_buf;
58
snprintf(temp_path, sizeof(temp_path), "%s", buf+1);
59
snprintf(buf, sizeof(buf), "%s%s", temp_path, fname_to_utf8(temp_home_str));
68
for(x = buf+1, y = name;
69
*x != '/' && *x != '\0' && y < name + sizeof(name)-1;
75
pw = getpwuid(getuid());
81
if(strlen(pw->pw_dir) + strlen(buf) > len) {
85
if((tbuf = (char *) malloc((len+1)*sizeof(char))) != NULL){
86
snprintf(tbuf, len, "%s%s", pw->pw_dir, x);
87
snprintf(buf, len, "%s", tbuf);
92
return(len ? buf : (char *)NULL);