tweaks: adjust indentation after previous change, reshuffle declarations

This commit is contained in:
Benno Schulenberg
2019-09-17 14:11:45 +02:00
parent b901a20a06
commit 4383b01b9b

View File

@@ -2307,44 +2307,42 @@ void do_savefile(void)
* Return an allocated string containing the expanded path. */ * Return an allocated string containing the expanded path. */
char *real_dir_from_tilde(const char *buf) char *real_dir_from_tilde(const char *buf)
{ {
char *retval; char *tilde_dir, *retval;
size_t i = 1;
if (*buf != '~') if (*buf != '~')
return mallocstrcpy(NULL, buf); return mallocstrcpy(NULL, buf);
size_t i = 1; /* Figure out how much of the string we need to compare. */
char *tilde_dir; while (buf[i] != '/' && buf[i] != '\0')
i++;
/* Figure out how much of the string we need to compare. */ if (i == 1) {
while (buf[i] != '/' && buf[i] != '\0') get_homedir();
i++; tilde_dir = mallocstrcpy(NULL, homedir);
} else {
if (i == 1) {
get_homedir();
tilde_dir = mallocstrcpy(NULL, homedir);
} else {
#ifdef HAVE_PWD_H #ifdef HAVE_PWD_H
const struct passwd *userdata; const struct passwd *userdata;
tilde_dir = mallocstrncpy(NULL, buf, i + 1); tilde_dir = mallocstrncpy(NULL, buf, i + 1);
tilde_dir[i] = '\0'; tilde_dir[i] = '\0';
do { do {
userdata = getpwent(); userdata = getpwent();
} while (userdata != NULL && } while (userdata != NULL &&
strcmp(userdata->pw_name, tilde_dir + 1) != 0); strcmp(userdata->pw_name, tilde_dir + 1) != 0);
endpwent(); endpwent();
if (userdata != NULL) if (userdata != NULL)
tilde_dir = mallocstrcpy(tilde_dir, userdata->pw_dir); tilde_dir = mallocstrcpy(tilde_dir, userdata->pw_dir);
#else #else
tilde_dir = strdup(""); tilde_dir = strdup("");
#endif #endif
} }
retval = charalloc(strlen(tilde_dir) + strlen(buf + i) + 1); retval = charalloc(strlen(tilde_dir) + strlen(buf + i) + 1);
sprintf(retval, "%s%s", tilde_dir, buf + i); sprintf(retval, "%s%s", tilde_dir, buf + i);
free(tilde_dir); free(tilde_dir);
return retval; return retval;
} }