summaryrefslogtreecommitdiff
path: root/deps/uv/src/unix/darwin.c
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2015-01-05 20:44:25 +0100
committerBen Noordhuis <info@bnoordhuis.nl>2015-01-05 22:25:20 +0100
commiteaed2a11ecf8d4f8a309f42d6bbc72306c01b755 (patch)
tree59abc7b7d4c1396c5bd60a47f13e694076b5b299 /deps/uv/src/unix/darwin.c
parent94e147500c5bf457c9101bda8c8020d8ff896708 (diff)
downloadandroid-node-v8-eaed2a11ecf8d4f8a309f42d6bbc72306c01b755.tar.gz
android-node-v8-eaed2a11ecf8d4f8a309f42d6bbc72306c01b755.tar.bz2
android-node-v8-eaed2a11ecf8d4f8a309f42d6bbc72306c01b755.zip
deps: update libuv to 1.2.0
PR-URL: https://github.com/iojs/io.js/pull/237 Reviewed-By: Bert Belder <bertbelder@gmail.com> Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Diffstat (limited to 'deps/uv/src/unix/darwin.c')
-rw-r--r--deps/uv/src/unix/darwin.c37
1 files changed, 21 insertions, 16 deletions
diff --git a/deps/uv/src/unix/darwin.c b/deps/uv/src/unix/darwin.c
index c9a45edee4..651545f85e 100644
--- a/deps/uv/src/unix/darwin.c
+++ b/deps/uv/src/unix/darwin.c
@@ -65,28 +65,33 @@ uint64_t uv__hrtime(uv_clocktype_t type) {
int uv_exepath(char* buffer, size_t* size) {
- uint32_t usize;
- int result;
- char* path;
- char* fullpath;
+ /* realpath(exepath) may be > PATH_MAX so double it to be on the safe side. */
+ char abspath[PATH_MAX * 2 + 1];
+ char exepath[PATH_MAX + 1];
+ uint32_t exepath_size;
+ size_t abspath_size;
- if (buffer == NULL || size == NULL)
+ if (buffer == NULL || size == NULL || *size == 0)
return -EINVAL;
- usize = *size;
- result = _NSGetExecutablePath(buffer, &usize);
- if (result) return result;
+ exepath_size = sizeof(exepath);
+ if (_NSGetExecutablePath(exepath, &exepath_size))
+ return -EIO;
- path = malloc(2 * PATH_MAX);
- fullpath = realpath(buffer, path);
- if (fullpath == NULL) {
- SAVE_ERRNO(free(path));
+ if (realpath(exepath, abspath) != abspath)
return -errno;
- }
- strncpy(buffer, fullpath, *size);
- free(fullpath);
- *size = strlen(buffer);
+ abspath_size = strlen(abspath);
+ if (abspath_size == 0)
+ return -EIO;
+
+ *size -= 1;
+ if (*size > abspath_size)
+ *size = abspath_size;
+
+ memcpy(buffer, abspath, *size);
+ buffer[*size] = '\0';
+
return 0;
}