unix: refactor uv_os_homedir to use uv_os_getenv
PR-URL: https://github.com/libuv/libuv/pull/1760 Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
parent
f60713f7cf
commit
b7f649d308
@ -1048,29 +1048,16 @@ int uv__dup2_cloexec(int oldfd, int newfd) {
|
||||
|
||||
int uv_os_homedir(char* buffer, size_t* size) {
|
||||
uv_passwd_t pwd;
|
||||
char* buf;
|
||||
size_t len;
|
||||
int r;
|
||||
|
||||
if (buffer == NULL || size == NULL || *size == 0)
|
||||
return UV_EINVAL;
|
||||
/* Check if the HOME environment variable is set first. The task of
|
||||
performing input validation on buffer and size is taken care of by
|
||||
uv_os_getenv(). */
|
||||
r = uv_os_getenv("HOME", buffer, size);
|
||||
|
||||
/* Check if the HOME environment variable is set first */
|
||||
buf = getenv("HOME");
|
||||
|
||||
if (buf != NULL) {
|
||||
len = strlen(buf);
|
||||
|
||||
if (len >= *size) {
|
||||
*size = len + 1;
|
||||
return UV_ENOBUFS;
|
||||
}
|
||||
|
||||
memcpy(buffer, buf, len + 1);
|
||||
*size = len;
|
||||
|
||||
return 0;
|
||||
}
|
||||
if (r != UV_ENOENT)
|
||||
return r;
|
||||
|
||||
/* HOME is not set, so call uv__getpwuid_r() */
|
||||
r = uv__getpwuid_r(&pwd);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user