From d4d1f328583bcadfdc652ec1cab32adef38f0465 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Mon, 15 Dec 2014 17:55:11 +0100 Subject: [PATCH] unix: change uv_cwd not to return a trailing slash This aligns the behavior with the Windows implementation. PR-URL: https://github.com/libuv/libuv/pull/63 Reviewed-By: Bert Belder Reviewed-By: Ben Noordhuis --- docs/src/misc.rst | 4 ++++ src/unix/core.c | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/docs/src/misc.rst b/docs/src/misc.rst index 3d1b11ca..10c349e9 100644 --- a/docs/src/misc.rst +++ b/docs/src/misc.rst @@ -207,6 +207,10 @@ API Gets the current working directory. + .. versionchanged:: 1.1.0 + + On Unix the path no longer ends in a slash. + .. c:function:: int uv_chdir(const char* dir) Changes the current working directory. diff --git a/src/unix/core.c b/src/unix/core.c index c08040e5..44995b22 100644 --- a/src/unix/core.c +++ b/src/unix/core.c @@ -635,6 +635,11 @@ int uv_cwd(char* buffer, size_t* size) { return -errno; *size = strlen(buffer); + if (*size > 1 && buffer[*size - 1] == '/') { + buffer[*size-1] = '\0'; + (*size)--; + } + return 0; }