-#if UDIR
-/*
- * Expand /u/username into the home directory for the specified user.
- * We could use the getpw stuff here, but then we would have to load
- * in stdio and who knows what else.
- */
-
-#define MAXLOGNAME 32
-#define MAXPWLINE 128
-
-char *pfgets();
-
-
-STATIC char *
-expudir(path)
- char *path;
- {
- register char *p, *q, *r;
- char name[MAXLOGNAME];
- char line[MAXPWLINE];
- int i;
-
- r = path; /* result on failure */
- p = r + 3; /* the 3 skips "/u/" */
- q = name;
- while (*p && *p != '/') {
- if (q >= name + MAXLOGNAME - 1)
- return r; /* fail, name too long */
- *q++ = *p++;
- }
- *q = '\0';
- setinputfile("/etc/passwd", 1);
- q = line + strlen(name);
- while (pfgets(line, MAXPWLINE) != NULL) {
- if (line[0] == name[0] && prefix(name, line) && *q == ':') {
- /* skip to start of home directory */
- i = 4;
- do {
- while (*++q && *q != ':');
- } while (--i > 0);
- if (*q == '\0')
- break; /* fail, corrupted /etc/passwd */
- q++;
- for (r = q ; *r && *r != '\n' && *r != ':' ; r++);
- *r = '\0'; /* nul terminate home directory */
- i = r - q; /* i = strlen(q) */
- r = stalloc(i + strlen(p) + 1);
- scopy(q, r);
- scopy(p, r + i);
- TRACE(("expudir converts %s to %s\n", path, r));
- didudir = 1;
- path = r; /* succeed */
- break;
- }
- }
- popfile();
- return r;
-}
-#endif
-
-