From 36ce474d14616b83db9e93d06a2dd7df788eb170 Mon Sep 17 00:00:00 2001 From: Alex Syrnikov Date: Fri, 21 Aug 2020 17:42:53 +0300 Subject: [PATCH 1/2] Fix typos in libbutl/path.mxx comments --- libbutl/path.mxx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libbutl/path.mxx b/libbutl/path.mxx index 1ee2a66c..d55841e9 100644 --- a/libbutl/path.mxx +++ b/libbutl/path.mxx @@ -105,7 +105,7 @@ LIBBUTL_MODEXPORT namespace butl using char_traits_type = typename string_type::traits_type; using size_type = typename string_type::size_type; - // Canonical directory and path seperators. + // Canonical directory and path separators. // #ifdef _WIN32 static constexpr const C directory_separator = '\\'; @@ -125,7 +125,7 @@ LIBBUTL_MODEXPORT namespace butl #endif // Directory separator tests. On some platforms there could be multiple - // seperators. For example, on Windows we check for both '/' and '\'. + // separators. For example, on Windows we check for both '/' and '\'. // static bool is_separator (C c) @@ -659,7 +659,7 @@ LIBBUTL_MODEXPORT namespace butl // necessary. Otherwise, return the empty object and leave the passed // string untouched. // - // If extact is false, throw invalid_path if the string is not a valid + // If exact is false, throw invalid_path if the string is not a valid // path (e.g., uses an unsupported path notation on Windows). // using data_type = path_data; From 84be35f21e03362d4931c991096492cda3478fae Mon Sep 17 00:00:00 2001 From: Alex Syrnikov Date: Fri, 21 Aug 2020 21:04:15 +0300 Subject: [PATCH 2/2] Fix getpwuid_r error handling from man getpwuid: "In case of error, an error number is returned, and NULL is stored in *result." Error returned, NOT -1 and errno. Example from man: if (result == NULL) { if (s == 0) printf("Not found\n"); else { errno = s; perror("getpwnam_r"); } exit(EXIT_FAILURE); } --- libbutl/path.cxx | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/libbutl/path.cxx b/libbutl/path.cxx index 3b047302..e20380e8 100644 --- a/libbutl/path.cxx +++ b/libbutl/path.cxx @@ -168,14 +168,17 @@ namespace butl passwd* rpw; int r (getpwuid_r (getuid (), &pw, buf, sizeof (buf), &rpw)); - if (r == -1) - throw_generic_error (errno); - - if (r == 0 && rpw == nullptr) - // According to POSIX errno should be left unchanged if an entry is not - // found. - // - throw_generic_error (ENOENT); + if (rpw == nullptr) + { + if (r == 0) + // According to POSIX errno should be left unchanged if an entry is not + // found. + throw_generic_error (ENOENT); + else { + errno = r; + throw_generic_error (errno); + } + } return pw.pw_dir; }