Path parse

Code
errr path_parse(char *buf, size_t max, cptr file) { 	cptr u, s; 	struct passwd 	*pw; char user[128]; /* Assume no result */ buf[0] = '\0'; /* No file? */ 	if (!file) return (-1); /* File needs no parsing */ if (file[0] != '~') { 		my_strcpy(buf, file, max); return (0); } 	/* Point at the user */ u = file+1; /* Look for non-user portion of the file */ s = strstr(u, PATH_SEP); /* Hack -- no long user names */ if (s && (s >= u + sizeof(user))) return (1); /* Extract a user name */ if (s) { 		int i; 		for (i = 0; u < s; ++i) user[i] = *u++; user[i] = '\0'; u = user; } 	/* Look up the "current" user */ if (u[0] == '\0') u = getlogin; /* Look up a user (or "current" user) */ if (u) pw = getpwnam(u); else pw = getpwuid(getuid); /* Nothing found? */ 	if (!pw) return (1); /* Make use of the info */ my_strcpy(buf, pw->pw_dir, max); /* Append the rest of the filename, if any */ if (s) my_strcat(buf, s, max); /* Success */ return (0); }

Found in
z-file.c