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:
Ben Noordhuis 2015-01-02 23:07:40 +01:00
parent af96f458e2
commit afb319215d
8 changed files with 11 additions and 7 deletions

View File

@ -294,7 +294,7 @@ int uv_exepath(char* buffer, size_t* size) {
int fd;
char **argv;
if ((buffer == NULL) || (size == NULL))
if (buffer == NULL || size == NULL || *size == 0)
return -EINVAL;
snprintf(pp, sizeof(pp), "/proc/%lu/psinfo", (unsigned long) getpid());

View File

@ -70,7 +70,7 @@ int uv_exepath(char* buffer, size_t* size) {
char* path;
char* fullpath;
if (buffer == NULL || size == NULL)
if (buffer == NULL || size == NULL || *size == 0)
return -EINVAL;
usize = *size;

View File

@ -78,7 +78,7 @@ int uv_exepath(char* buffer, size_t* size) {
int mib[4];
size_t cb;
if (buffer == NULL || size == NULL)
if (buffer == NULL || size == NULL || *size == 0)
return -EINVAL;
#ifdef __DragonFly__

View File

@ -378,7 +378,7 @@ void uv_loadavg(double avg[3]) {
int uv_exepath(char* buffer, size_t* size) {
ssize_t n;
if (buffer == NULL || size == NULL)
if (buffer == NULL || size == NULL || *size == 0)
return -EINVAL;
n = readlink("/proc/self/exe", buffer, *size - 1);

View File

@ -83,7 +83,7 @@ int uv_exepath(char* buffer, size_t* size) {
size_t cb;
pid_t mypid;
if (buffer == NULL || size == NULL)
if (buffer == NULL || size == NULL || *size == 0)
return -EINVAL;
mypid = getpid();

View File

@ -85,7 +85,7 @@ int uv_exepath(char* buffer, size_t* size) {
pid_t mypid;
int err;
if (buffer == NULL || size == NULL)
if (buffer == NULL || size == NULL || *size == 0)
return -EINVAL;
mypid = getpid();

View File

@ -300,7 +300,7 @@ int uv_exepath(char* buffer, size_t* size) {
ssize_t res;
char buf[128];
if (buffer == NULL || size == NULL)
if (buffer == NULL || size == NULL || *size == 0)
return -EINVAL;
snprintf(buf, sizeof(buf), "/proc/%lu/path/a.out", (unsigned long) getpid());

View File

@ -61,5 +61,9 @@ TEST_IMPL(get_currentexe) {
r = uv_exepath(buffer, NULL);
ASSERT(r == UV_EINVAL);
size = 0;
r = uv_exepath(buffer, &size);
ASSERT(r == UV_EINVAL);
return 0;
}