Commit Graph

9 Commits

Author SHA1 Message Date
Ben Noordhuis
555a9647a0 linux: fix uv_exepath(size=1) UV_EINVAL error
uv_exepath() should write as much as possible to the output buffer.
In the case of size=1, skip the call to readlink() because it will
fail with EINVAL; just write the terminating zero byte.

PR-URL: https://github.com/libuv/libuv/pull/104
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-01-03 23:40:31 +01:00
Ben Noordhuis
885b1ecda0 darwin: fix uv_exepath(smallbuf) UV_EPERM error
Passing a buffer that was too small to hold the result made it fail
with UV_EPERM because the -1 status code from _NSGetExecutablePath()
was returned unmodified to the caller.

This commit rewrites uv_exepath() to:

1. Not allocate heap memory, and

2. Not clobber the result buffer on error, and

3. Handle _NSGetExecutablePath()'s and realpath()'s idiosyncracies, and

4. Store as much of the path in the output buffer as possible, don't
   fail with an error.  Makes it behave the same as other platforms.
   The result is always zero-terminated.

Fixes: https://github.com/libuv/libuv/issues/103
PR-URL: https://github.com/libuv/libuv/pull/104
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-01-03 23:40:24 +01:00
Ben Noordhuis
afb319215d 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>
2015-01-03 23:39:55 +01:00
Ben Noordhuis
f5baf210df test: wrap long lines at 80 columns 2013-09-11 17:29:43 +02:00
Ben Noordhuis
3ee4d3f183 unix, windows: return error codes directly
This commit changes the libuv API to return error codes directly rather
than storing them in a loop-global field.

A code snippet like this one:

    if (uv_foo(loop) < 0) {
      uv_err_t err = uv_last_error(loop);
      fprintf(stderr, "%s\n", uv_strerror(err));
    }

Should be rewritten like this:

    int err = uv_foo(loop);
    if (err < 0)
      fprintf(stderr, "%s\n", uv_strerror(err));

The rationale for this change is that it should make creating bindings
for other languages a lot easier: dealing with struct return values is
painful with most FFIs and often downright buggy.
2013-07-07 09:51:00 +02:00
Erick Tryzelaar
f4e2d5559f Fix test-get-currentexe on darwin.
Darwin uses _NSGetExecutablePath to determine
the path of an executable, but that can return
an absolute path. This patch tweaks the executable
path to strip off a potential "./" prefix from
argv[0], which fixes the test.
2011-09-08 14:20:06 -07:00
Ryan Dahl
ce8ff3031c src/ and include/ directories
Helps #71 but does not update the MSVC files.
2011-07-07 07:52:57 -07:00
Ryan Dahl
7b56134f73 Rename uv_get_hrtime, uv_get_exepath to uv_hrtime, uv_exepath 2011-06-28 14:26:28 +02:00
Igor Zinkovsky
9fc8a7f167 Adds uv_get_exepath API
Only works on Linux, Mac, Windows currently.
2011-05-24 08:40:27 -07:00