strbuf: use strbuf_addstr() for adding C strings

Avoid code duplication and let strbuf_addstr() call strlen() for us.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
René Scharfe
2014-07-17 01:38:18 +02:00
committed by Junio C Hamano
parent 9d02150cf4
commit cedc61a998
3 changed files with 10 additions and 10 deletions

6
path.c
View File

@ -277,16 +277,16 @@ char *expand_user_path(const char *path)
const char *home = getenv("HOME");
if (!home)
goto return_null;
strbuf_add(&user_path, home, strlen(home));
strbuf_addstr(&user_path, home);
} else {
struct passwd *pw = getpw_str(username, username_len);
if (!pw)
goto return_null;
strbuf_add(&user_path, pw->pw_dir, strlen(pw->pw_dir));
strbuf_addstr(&user_path, pw->pw_dir);
}
to_copy = first_slash;
}
strbuf_add(&user_path, to_copy, strlen(to_copy));
strbuf_addstr(&user_path, to_copy);
return strbuf_detach(&user_path, NULL);
return_null:
strbuf_release(&user_path);