unix: make uv_exepath(size=0) return UV_EINVAL
Make the behavior of a call to uv_exepath() with a size argument of zero consistent with the Windows implementation where it returns UV_EINVAL. PR-URL: https://github.com/libuv/libuv/pull/104 Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
This commit is contained in:
parent
af96f458e2
commit
afb319215d
@ -294,7 +294,7 @@ int uv_exepath(char* buffer, size_t* size) {
|
|||||||
int fd;
|
int fd;
|
||||||
char **argv;
|
char **argv;
|
||||||
|
|
||||||
if ((buffer == NULL) || (size == NULL))
|
if (buffer == NULL || size == NULL || *size == 0)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
snprintf(pp, sizeof(pp), "/proc/%lu/psinfo", (unsigned long) getpid());
|
snprintf(pp, sizeof(pp), "/proc/%lu/psinfo", (unsigned long) getpid());
|
||||||
|
|||||||
@ -70,7 +70,7 @@ int uv_exepath(char* buffer, size_t* size) {
|
|||||||
char* path;
|
char* path;
|
||||||
char* fullpath;
|
char* fullpath;
|
||||||
|
|
||||||
if (buffer == NULL || size == NULL)
|
if (buffer == NULL || size == NULL || *size == 0)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
usize = *size;
|
usize = *size;
|
||||||
|
|||||||
@ -78,7 +78,7 @@ int uv_exepath(char* buffer, size_t* size) {
|
|||||||
int mib[4];
|
int mib[4];
|
||||||
size_t cb;
|
size_t cb;
|
||||||
|
|
||||||
if (buffer == NULL || size == NULL)
|
if (buffer == NULL || size == NULL || *size == 0)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
#ifdef __DragonFly__
|
#ifdef __DragonFly__
|
||||||
|
|||||||
@ -378,7 +378,7 @@ void uv_loadavg(double avg[3]) {
|
|||||||
int uv_exepath(char* buffer, size_t* size) {
|
int uv_exepath(char* buffer, size_t* size) {
|
||||||
ssize_t n;
|
ssize_t n;
|
||||||
|
|
||||||
if (buffer == NULL || size == NULL)
|
if (buffer == NULL || size == NULL || *size == 0)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
n = readlink("/proc/self/exe", buffer, *size - 1);
|
n = readlink("/proc/self/exe", buffer, *size - 1);
|
||||||
|
|||||||
@ -83,7 +83,7 @@ int uv_exepath(char* buffer, size_t* size) {
|
|||||||
size_t cb;
|
size_t cb;
|
||||||
pid_t mypid;
|
pid_t mypid;
|
||||||
|
|
||||||
if (buffer == NULL || size == NULL)
|
if (buffer == NULL || size == NULL || *size == 0)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
mypid = getpid();
|
mypid = getpid();
|
||||||
|
|||||||
@ -85,7 +85,7 @@ int uv_exepath(char* buffer, size_t* size) {
|
|||||||
pid_t mypid;
|
pid_t mypid;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (buffer == NULL || size == NULL)
|
if (buffer == NULL || size == NULL || *size == 0)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
mypid = getpid();
|
mypid = getpid();
|
||||||
|
|||||||
@ -300,7 +300,7 @@ int uv_exepath(char* buffer, size_t* size) {
|
|||||||
ssize_t res;
|
ssize_t res;
|
||||||
char buf[128];
|
char buf[128];
|
||||||
|
|
||||||
if (buffer == NULL || size == NULL)
|
if (buffer == NULL || size == NULL || *size == 0)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
snprintf(buf, sizeof(buf), "/proc/%lu/path/a.out", (unsigned long) getpid());
|
snprintf(buf, sizeof(buf), "/proc/%lu/path/a.out", (unsigned long) getpid());
|
||||||
|
|||||||
@ -61,5 +61,9 @@ TEST_IMPL(get_currentexe) {
|
|||||||
r = uv_exepath(buffer, NULL);
|
r = uv_exepath(buffer, NULL);
|
||||||
ASSERT(r == UV_EINVAL);
|
ASSERT(r == UV_EINVAL);
|
||||||
|
|
||||||
|
size = 0;
|
||||||
|
r = uv_exepath(buffer, &size);
|
||||||
|
ASSERT(r == UV_EINVAL);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user