- Timestamp:
- Dec 6, 2003, 9:13:39 PM (21 years ago)
- Branches:
- master, barnowl_perlaim, debian, owl, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
- Children:
- 88ca489
- Parents:
- a68f05d
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
util.c
r12c35df rf36222f 4 4 #include <unistd.h> 5 5 #include <ctype.h> 6 #include <pwd.h> 6 7 7 8 static const char fileIdent[] = "$Id$"; … … 175 176 } 176 177 return buff; 178 } 179 180 /* Return a "nice" version of the path. Tilde expansion is done, and 181 * duplicate slashes are removed. Caller must free the return. 182 */ 183 char *owl_util_makepath(char *in) 184 { 185 int i, j, x; 186 char *out, user[MAXPATHLEN]; 187 struct passwd *pw; 188 189 out=owl_malloc(MAXPATHLEN+1); 190 out[0]='\0'; 191 j=strlen(in); 192 x=0; 193 for (i=0; i<j; i++) { 194 if (in[i]=='~') { 195 if ( (i==(j-1)) || /* last character */ 196 (in[i+1]=='/') ) { /* ~/ */ 197 /* use my homedir */ 198 pw=getpwuid(getuid()); 199 if (!pw) { 200 out[x]=in[i]; 201 } else { 202 out[x]='\0'; 203 strcat(out, pw->pw_dir); 204 x+=strlen(pw->pw_dir); 205 } 206 } else { 207 /* another user homedir */ 208 int a, b; 209 b=0; 210 for (a=i+1; i<j; a++) { 211 if (in[a]==' ' || in[a]=='/') { 212 break; 213 } else { 214 user[b]=in[a]; 215 i++; 216 b++; 217 } 218 } 219 user[b]='\0'; 220 pw=getpwnam(user); 221 if (!pw) { 222 out[x]==in[i]; 223 } else { 224 out[x]='\0'; 225 strcat(out, pw->pw_dir); 226 x+=strlen(pw->pw_dir); 227 } 228 } 229 } else if (in[i]=='/') { 230 /* check for a double / */ 231 if (i<(j-1) && (in[i+1]=='/')) { 232 /* do nothing */ 233 } else { 234 out[x]=in[i]; 235 x++; 236 } 237 } else { 238 out[x]=in[i]; 239 x++; 240 } 241 } 242 out[x]='\0'; 243 return(out); 177 244 } 178 245
Note: See TracChangeset
for help on using the changeset viewer.