diff --git a/src/builtin.cpp b/src/builtin.cpp index be3c98fbe..76e235813 100644 --- a/src/builtin.cpp +++ b/src/builtin.cpp @@ -19,7 +19,7 @@ #include #include -#include +#include #include #include @@ -97,7 +97,7 @@ int builtin_count_args(const wchar_t *const *argv) { /// This function works like wperror, but it prints its result into the streams.err string instead /// to stderr. Used by the builtin commands. void builtin_wperror(const wchar_t *s, io_streams_t &streams) { - char *err = strerror(errno); + char *err = std::strerror(errno); if (s != NULL) { streams.err.append(s); streams.err.append(L": "); diff --git a/src/builtin_math.cpp b/src/builtin_math.cpp index a1fb48d25..7798fe1a8 100644 --- a/src/builtin_math.cpp +++ b/src/builtin_math.cpp @@ -3,7 +3,7 @@ #include #include -#include +#include #include #include diff --git a/src/builtin_printf.cpp b/src/builtin_printf.cpp index 1bcf05cc8..d12d9c596 100644 --- a/src/builtin_printf.cpp +++ b/src/builtin_printf.cpp @@ -57,7 +57,7 @@ #include #include #include -#include +#include #include #include #include @@ -238,7 +238,7 @@ void builtin_printf_state_t::verify_numeric(const wchar_t *s, const wchar_t *end if (errcode == ERANGE) { this->fatal_error(L"%ls: %ls", s, _(L"Number out of range")); } else { - this->fatal_error(L"%ls: %s", s, strerror(errcode)); + this->fatal_error(L"%ls: %s", s, std::strerror(errcode)); } } else if (*end) { if (s == end) diff --git a/src/builtin_pwd.cpp b/src/builtin_pwd.cpp index ca668b0ea..66fb64efc 100644 --- a/src/builtin_pwd.cpp +++ b/src/builtin_pwd.cpp @@ -1,7 +1,7 @@ // Implementation of the pwd builtin. #include "config.h" // IWYU pragma: keep -#include +#include #include "builtin.h" #include "builtin_pwd.h" @@ -58,7 +58,7 @@ int builtin_pwd(parser_t &parser, io_streams_t &streams, wchar_t **argv) { if (auto real_pwd = wrealpath(pwd)) { pwd = std::move(*real_pwd); } else { - const char *error = strerror(errno); + const char *error = std::strerror(errno); streams.err.append_format(L"%ls: realpath failed:", cmd, error); return STATUS_CMD_ERROR; } diff --git a/src/builtin_read.cpp b/src/builtin_read.cpp index 523fb2d9e..a0f1ab91a 100644 --- a/src/builtin_read.cpp +++ b/src/builtin_read.cpp @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include @@ -319,7 +319,7 @@ static int read_one_char_at_a_time(int fd, wcstring &buff, int nchars, bool spli } else { size_t sz = std::mbrtowc(&res, &b, 1, &state); if (sz == (size_t)-1) { - memset(&state, 0, sizeof(state)); + std::memset(&state, 0, sizeof(state)); } else if (sz != (size_t)-2) { finished = true; } diff --git a/src/builtin_realpath.cpp b/src/builtin_realpath.cpp index 552eae5c1..62edae85b 100644 --- a/src/builtin_realpath.cpp +++ b/src/builtin_realpath.cpp @@ -3,7 +3,7 @@ #include #include -#include +#include #include #include "builtin.h" @@ -43,7 +43,7 @@ int builtin_realpath(parser_t &parser, io_streams_t &streams, wchar_t **argv) { // realpath() just couldn't do it. Report the error and make it clear // this is an error from our builtin, not the system's realpath. streams.err.append_format(L"builtin %ls: %ls: %s\n", cmd, argv[optind], - strerror(errno)); + std::strerror(errno)); } else { // Who knows. Probably a bug in our wrealpath() implementation. streams.err.append_format(_(L"builtin %ls: Invalid path: %ls\n"), cmd, argv[optind]); diff --git a/src/builtin_set.cpp b/src/builtin_set.cpp index c57b1d60f..3a18e5a09 100644 --- a/src/builtin_set.cpp +++ b/src/builtin_set.cpp @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include #include #include @@ -295,7 +295,7 @@ static bool validate_path_warning_on_colons(const wchar_t *cmd, any_success = true; } else if (looks_like_colon_sep) { streams.err.append_format(BUILTIN_SET_PATH_ERROR, cmd, key, dir.c_str(), - strerror(errno)); + std::strerror(errno)); streams.err.append_format(BUILTIN_SET_PATH_HINT, cmd, key, key, std::wcschr(dir.c_str(), L':') + 1); } diff --git a/src/builtin_test.cpp b/src/builtin_test.cpp index b49fa7bb6..3951a7ecc 100644 --- a/src/builtin_test.cpp +++ b/src/builtin_test.cpp @@ -5,7 +5,7 @@ #include #include -#include +#include #include #include #include @@ -675,7 +675,7 @@ static bool parse_number(const wcstring &arg, number_t *number, wcstring_list_t errors.push_back(format_string(_(L"Integer %lld in '%ls' followed by non-digit"), integral, argcs)); } else { - errors.push_back(format_string(L"%s: '%ls'", strerror(errno), argcs)); + errors.push_back(format_string(L"%s: '%ls'", std::strerror(errno), argcs)); } return false; } diff --git a/src/color.cpp b/src/color.cpp index 4dd60ef46..ceaec1ffd 100644 --- a/src/color.cpp +++ b/src/color.cpp @@ -11,7 +11,7 @@ #include "fallback.h" // IWYU pragma: keep bool rgb_color_t::try_parse_special(const wcstring &special) { - memset(&data, 0, sizeof data); + std::memset(&data, 0, sizeof data); const wchar_t *name = special.c_str(); if (!wcscasecmp(name, L"normal")) { this->type = type_normal; @@ -108,7 +108,7 @@ static unsigned char convert_color(const unsigned char rgb[3], const uint32_t *c } bool rgb_color_t::try_parse_rgb(const wcstring &name) { - memset(&data, 0, sizeof data); + std::memset(&data, 0, sizeof data); // We support the following style of rgb formats (case insensitive): // #FA3 // #F3A035 @@ -185,7 +185,7 @@ wcstring_list_t rgb_color_t::named_color_names() { } bool rgb_color_t::try_parse_named(const wcstring &str) { - memset(&data, 0, sizeof data); + std::memset(&data, 0, sizeof data); size_t max = sizeof named_colors / sizeof *named_colors; for (size_t idx = 0; idx < max; idx++) { if (0 == wcscasecmp(str.c_str(), named_colors[idx].name)) { @@ -299,7 +299,7 @@ void rgb_color_t::parse(const wcstring &str) { if (!success) success = try_parse_named(str); if (!success) success = try_parse_rgb(str); if (!success) { - memset(&this->data, 0, sizeof this->data); + std::memset(&this->data, 0, sizeof this->data); this->type = type_none; } } diff --git a/src/color.h b/src/color.h index ec6d29dbb..2e437b966 100644 --- a/src/color.h +++ b/src/color.h @@ -2,7 +2,7 @@ #ifndef FISH_COLOR_H #define FISH_COLOR_H -#include +#include #include @@ -159,7 +159,7 @@ class rgb_color_t { /// Compare two colors for equality. bool operator==(const rgb_color_t &other) const { - return type == other.type && !memcmp(&data, &other.data, sizeof data); + return type == other.type && !std::memcmp(&data, &other.data, sizeof data); } /// Compare two colors for inequality. diff --git a/src/common.cpp b/src/common.cpp index ba7da173d..cb158912f 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include #include #include @@ -141,7 +141,7 @@ long convert_digit(wchar_t d, int base) { } /// Test whether the char is a valid hex digit as used by the `escape_string_*()` functions. -static bool is_hex_digit(int c) { return strchr("0123456789ABCDEF", c) != NULL; } +static bool is_hex_digit(int c) { return std::strchr("0123456789ABCDEF", c) != NULL; } /// This is a specialization of `convert_digit()` that only handles base 16 and only uppercase. long convert_hex_digit(wchar_t d) { @@ -170,8 +170,8 @@ bool is_windows_subsystem_for_linux() { uname(&info); // Sample utsname.release under WSL: 4.4.0-17763-Microsoft - if (strstr(info.release, "Microsoft") != nullptr) { - const char *dash = strchr(info.release, '-'); + if (std::strstr(info.release, "Microsoft") != nullptr) { + const char *dash = std::strchr(info.release, '-'); if (dash == nullptr || strtod(dash + 1, nullptr) < 17763) { debug(1, "This version of WSL is not supported and fish will probably not work correctly!\n" "Please upgrade to Windows 10 1809 (17763) or higher to use fish!"); @@ -346,11 +346,11 @@ static wcstring str2wcs_internal(const char *in, const size_t in_len) { wc = ENCODE_DIRECT_BASE + (unsigned char)in[in_pos]; result.push_back(wc); in_pos++; - memset(&state, 0, sizeof state); + std::memset(&state, 0, sizeof state); } else if (ret == 0) { // embedded null byte! result.push_back(L'\0'); in_pos++; - memset(&state, 0, sizeof state); + std::memset(&state, 0, sizeof state); } else { // normal case result.push_back(wc); in_pos += ret; @@ -362,7 +362,7 @@ static wcstring str2wcs_internal(const char *in, const size_t in_len) { wcstring str2wcstring(const char *in, size_t len) { return str2wcs_internal(in, len); } -wcstring str2wcstring(const char *in) { return str2wcs_internal(in, strlen(in)); } +wcstring str2wcstring(const char *in) { return str2wcs_internal(in, std::strlen(in)); } wcstring str2wcstring(const std::string &in) { // Handles embedded nulls! @@ -423,11 +423,11 @@ std::string wcs2string(const wcstring &input) { converted[0] = wc; result.append(converted, 1); } else { - memset(converted, 0, sizeof converted); + std::memset(converted, 0, sizeof converted); size_t len = std::wcrtomb(converted, wc, &state); if (len == (size_t)-1) { debug(1, L"Wide character U+%4X has no narrow representation", wc); - memset(&state, 0, sizeof(state)); + std::memset(&state, 0, sizeof(state)); } else { result.append(converted, len); } @@ -467,7 +467,7 @@ static char *wcs2str_internal(const wchar_t *in, char *out) { size_t len = std::wcrtomb(&out[out_pos], in[in_pos], &state); if (len == (size_t)-1) { debug(1, L"Wide character U+%4X has no narrow representation", in[in_pos]); - memset(&state, 0, sizeof(state)); + std::memset(&state, 0, sizeof(state)); } else { out_pos += len; } @@ -707,8 +707,8 @@ void debug_safe(int level, const char *msg, const char *param1, const char *para size_t param_idx = 0; const char *cursor = msg; while (*cursor != '\0') { - const char *end = strchr(cursor, '%'); - if (end == NULL) end = cursor + strlen(cursor); + const char *end = std::strchr(cursor, '%'); + if (end == NULL) end = cursor + std::strlen(cursor); ignore_result(write(STDERR_FILENO, cursor, end - cursor)); @@ -717,7 +717,7 @@ void debug_safe(int level, const char *msg, const char *param1, const char *para assert(param_idx < sizeof params / sizeof *params); const char *format = params[param_idx++]; if (!format) format = "(null)"; - ignore_result(write(STDERR_FILENO, format, strlen(format))); + ignore_result(write(STDERR_FILENO, format, std::strlen(format))); cursor = end + 2; } else if (end[0] == '\0') { // Must be at the end of the string. @@ -2138,7 +2138,7 @@ void append_str(char *buff, const char *str, size_t *inout_idx, size_t max_len) void format_size_safe(char buff[128], unsigned long long sz) { const size_t buff_size = 128; const size_t max_len = buff_size - 1; // need to leave room for a null terminator - memset(buff, 0, buff_size); + std::memset(buff, 0, buff_size); size_t idx = 0; const char *const sz_name[] = {"kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB", NULL}; if (sz < 1) { @@ -2403,7 +2403,7 @@ void redirect_tty_output() { [[noreturn]] void __fish_assert(const char *msg, const char *file, size_t line, int error) { if (error) { debug(0, L"%s:%zu: failed assertion: %s: errno %d (%s)", file, line, msg, error, - strerror(error)); + std::strerror(error)); } else { debug(0, L"%s:%zu: failed assertion: %s", file, line, msg); } diff --git a/src/env.cpp b/src/env.cpp index 13d95763e..40bc26b34 100644 --- a/src/env.cpp +++ b/src/env.cpp @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include #include #include @@ -411,7 +411,7 @@ static void init_locale(const environment_t &vars) { debug(5, L"old LC_MESSAGES locale: '%s'", old_msg_locale); debug(5, L"new LC_MESSAGES locale: '%s'", new_msg_locale); #ifdef HAVE__NL_MSG_CAT_CNTR - if (strcmp(old_msg_locale, new_msg_locale)) { + if (std::strcmp(old_msg_locale, new_msg_locale)) { // Make change known to GNU gettext. extern int _nl_msg_cat_cntr; _nl_msg_cat_cntr++; @@ -455,7 +455,7 @@ static bool does_term_support_setting_title(const environment_t &vars) { char buf[PATH_MAX]; int retval = ttyname_r(STDIN_FILENO, buf, PATH_MAX); - if (retval != 0 || strstr(buf, "tty") || strstr(buf, "/vc/")) return false; + if (retval != 0 || std::strstr(buf, "tty") || std::strstr(buf, "/vc/")) return false; } return true; diff --git a/src/env_universal_common.cpp b/src/env_universal_common.cpp index f30cbad56..cde707860 100644 --- a/src/env_universal_common.cpp +++ b/src/env_universal_common.cpp @@ -17,7 +17,7 @@ #include #include #include -#include +#include #ifdef __CYGWIN__ #include #endif @@ -123,7 +123,7 @@ static maybe_t default_vars_path() { /// On success, updates the cursor to just past the command. static bool match(const wchar_t **inout_cursor, const char *cmd) { const wchar_t *cursor = *inout_cursor; - size_t len = strlen(cmd); + size_t len = std::strlen(cmd); if (!std::equal(cmd, cmd + len, cursor)) { return false; } @@ -445,7 +445,7 @@ bool env_universal_t::write_to_fd(int fd, const wcstring &path) { bool success = true; std::string contents = serialize_with_vars(vars); if (write_loop(fd, contents.data(), contents.size()) < 0) { - const char *error = strerror(errno); + const char *error = std::strerror(errno); debug(0, _(L"Unable to write to universal variables file '%ls': %s"), path.c_str(), error); success = false; } @@ -460,7 +460,7 @@ bool env_universal_t::write_to_fd(int fd, const wcstring &path) { bool env_universal_t::move_new_vars_file_into_place(const wcstring &src, const wcstring &dst) { int ret = wrename(src, dst); if (ret != 0) { - const char *error = strerror(errno); + const char *error = std::strerror(errno); debug(0, _(L"Unable to rename file from '%ls' to '%ls': %s"), src.c_str(), dst.c_str(), error); } @@ -521,7 +521,7 @@ bool env_universal_t::open_temporary_file(const wcstring &directory, wcstring *o } if (!success) { - const char *error = strerror(saved_errno); + const char *error = std::strerror(saved_errno); debug(0, _(L"Unable to open temporary file '%ls': %s"), out_path->c_str(), error); } return success; @@ -583,7 +583,7 @@ bool env_universal_t::open_and_acquire_lock(const wcstring &path, int *out_fd) { continue; } #endif - const char *error = strerror(errno); + const char *error = std::strerror(errno); debug(0, _(L"Unable to open universal variable file '%ls': %s"), path.c_str(), error); break; } @@ -801,7 +801,7 @@ uvar_format_t env_universal_t::format_for_contents(const std::string &s) { if (sscanf(line.c_str(), "# VERSION: %64s", versionbuf) != 1) continue; // Try reading the version. - if (!strcmp(versionbuf, UVARS_VERSION_3_0)) { + if (!std::strcmp(versionbuf, UVARS_VERSION_3_0)) { return uvar_format_t::fish_3_0; } else { // Unknown future version. @@ -946,7 +946,7 @@ static bool get_mac_address(unsigned char macaddr[MAC_ADDRESS_MAX_LEN], strncpy((char *)r.ifr_name, interface, sizeof r.ifr_name - 1); r.ifr_name[sizeof r.ifr_name - 1] = 0; if (ioctl(dummy, SIOCGIFHWADDR, &r) >= 0) { - memcpy(macaddr, r.ifr_hwaddr.sa_data, MAC_ADDRESS_MAX_LEN); + std::memcpy(macaddr, r.ifr_hwaddr.sa_data, MAC_ADDRESS_MAX_LEN); result = true; } close(dummy); @@ -978,7 +978,7 @@ static bool get_mac_address(unsigned char macaddr[MAC_ADDRESS_MAX_LEN], size_t alen = sdl.sdl_alen; if (alen > MAC_ADDRESS_MAX_LEN) alen = MAC_ADDRESS_MAX_LEN; - memcpy(macaddr, sdl.sdl_data + sdl.sdl_nlen, alen); + std::memcpy(macaddr, sdl.sdl_data + sdl.sdl_nlen, alen); ok = true; break; } @@ -1053,7 +1053,7 @@ class universal_notifier_shmem_poller_t : public universal_notifier_t { bool errored = false; int fd = shm_open(path, O_RDWR | O_CREAT, 0600); if (fd < 0) { - const char *error = strerror(errno); + const char *error = std::strerror(errno); debug(0, _(L"Unable to open shared memory with path '%s': %s"), path, error); errored = true; } @@ -1063,7 +1063,7 @@ class universal_notifier_shmem_poller_t : public universal_notifier_t { if (!errored) { struct stat buf = {}; if (fstat(fd, &buf) < 0) { - const char *error = strerror(errno); + const char *error = std::strerror(errno); debug(0, _(L"Unable to fstat shared memory object with path '%s': %s"), path, error); errored = true; @@ -1074,7 +1074,7 @@ class universal_notifier_shmem_poller_t : public universal_notifier_t { // Set the size, if it's too small. bool set_size = !errored && size < (off_t)sizeof(universal_notifier_shmem_t); if (set_size && ftruncate(fd, sizeof(universal_notifier_shmem_t)) < 0) { - const char *error = strerror(errno); + const char *error = std::strerror(errno); debug(0, _(L"Unable to truncate shared memory object with path '%s': %s"), path, error); errored = true; } @@ -1084,7 +1084,7 @@ class universal_notifier_shmem_poller_t : public universal_notifier_t { void *addr = mmap(NULL, sizeof(universal_notifier_shmem_t), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (addr == MAP_FAILED) { - const char *error = strerror(errno); + const char *error = std::strerror(errno); debug(0, _(L"Unable to memory map shared memory object with path '%s': %s"), path, error); this->region = NULL; @@ -1489,7 +1489,7 @@ void universal_notifier_named_pipe_t::make_pipe(const wchar_t *test_path) { int mkfifo_status = mkfifo(narrow_path.c_str(), 0600); if (mkfifo_status == -1 && errno != EEXIST) { - const char *error = strerror(errno); + const char *error = std::strerror(errno); const wchar_t *errmsg = _(L"Unable to make a pipe for universal variables using '%ls': %s"); debug(0, errmsg, vars_path.c_str(), error); pipe_fd = -1; @@ -1498,7 +1498,7 @@ void universal_notifier_named_pipe_t::make_pipe(const wchar_t *test_path) { int fd = wopen_cloexec(vars_path, O_RDWR | O_NONBLOCK, 0600); if (fd < 0) { - const char *error = strerror(errno); + const char *error = std::strerror(errno); const wchar_t *errmsg = _(L"Unable to open a pipe for universal variables using '%ls': %s"); debug(0, errmsg, vars_path.c_str(), error); pipe_fd = -1; diff --git a/src/exec.cpp b/src/exec.cpp index 7d55ca99e..05ebea52a 100644 --- a/src/exec.cpp +++ b/src/exec.cpp @@ -14,7 +14,7 @@ #include #endif #include -#include +#include #include #include #include @@ -78,7 +78,7 @@ static bool redirection_is_to_real_file(const shared_ptr &io) { if (io && io->io_mode == io_mode_t::file) { // It's a file redirection. Compare the path to /dev/null. const char *path = static_cast(io.get())->filename_cstr; - if (strcmp(path, "/dev/null") != 0) { + if (std::strcmp(path, "/dev/null") != 0) { // It's not /dev/null. result = true; } @@ -104,9 +104,9 @@ char *get_interpreter(const char *command, char *interpreter, size_t buff_size) close(fd); } - if (strncmp(interpreter, "#! /", 4) == 0) { + if (std::strncmp(interpreter, "#! /", 4) == 0) { return interpreter + 3; - } else if (strncmp(interpreter, "#!/", 3) == 0) { + } else if (std::strncmp(interpreter, "#!/", 3) == 0) { return interpreter + 2; } @@ -1126,7 +1126,7 @@ static int exec_subshell_internal(const wcstring &cmd, parser_t &parser, wcstrin const char *cursor = begin; while (cursor < end) { // Look for the next separator. - const char *stop = (const char *)memchr(cursor, '\n', end - cursor); + const char *stop = (const char *)std::memchr(cursor, '\n', end - cursor); const bool hit_separator = (stop != NULL); if (!hit_separator) { // If it's not found, just use the end. diff --git a/src/expand.cpp b/src/expand.cpp index 4c7532fc8..42c44d8fa 100644 --- a/src/expand.cpp +++ b/src/expand.cpp @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #include #include @@ -1156,7 +1156,7 @@ expand_error_t expand_to_command_and_args(const wcstring &instr, const environme static std::string escape_single_quoted_hack_hack_hack_hack(const char *str) { std::string result; - size_t len = strlen(str); + size_t len = std::strlen(str); result.reserve(len + 2); result.push_back('\''); for (size_t i = 0; i < len; i++) { diff --git a/src/fallback.cpp b/src/fallback.cpp index f028e3f05..b944c0406 100644 --- a/src/fallback.cpp +++ b/src/fallback.cpp @@ -14,7 +14,7 @@ #include // IWYU pragma: keep #include // IWYU pragma: keep #include -#include +#include #include // IWYU pragma: keep #include // IWYU pragma: keep #include @@ -81,7 +81,7 @@ int fish_mkstemp_cloexec(char *name_template) { return 0; } - memcpy(out, in, sizeof(wchar_t) * (len + 1)); + std::memcpy(out, in, sizeof(wchar_t) * (len + 1)); return out; } diff --git a/src/fish.cpp b/src/fish.cpp index 4ec0ab190..21832b265 100644 --- a/src/fish.cpp +++ b/src/fish.cpp @@ -27,7 +27,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA #include #include #include -#include +#include #include #include #include @@ -69,9 +69,9 @@ class fish_cmd_opts_t { static const char *s_profiling_output_filename = NULL; static bool has_suffix(const std::string &path, const char *suffix, bool ignore_case) { - size_t pathlen = path.size(), suffixlen = strlen(suffix); + size_t pathlen = path.size(), suffixlen = std::strlen(suffix); return pathlen >= suffixlen && - !(ignore_case ? strcasecmp : strcmp)(path.c_str() + pathlen - suffixlen, suffix); + !(ignore_case ? strcasecmp : std::strcmp)(path.c_str() + pathlen - suffixlen, suffix); } /// Modifies the given path by calling realpath. Returns true if realpath succeeded, false @@ -122,7 +122,7 @@ static struct config_paths_t determine_config_directory_paths(const char *argv0) bool seems_installed = (suffix == installed_suffix); wcstring base_path = str2wcstring(exec_path); - base_path.resize(base_path.size() - strlen(suffix)); + base_path.resize(base_path.size() - std::strlen(suffix)); paths.data = base_path + (seems_installed ? L"/share/fish" : L"/share"); paths.sysconf = base_path + (seems_installed ? L"/etc/fish" : L"/etc"); diff --git a/src/fish_indent.cpp b/src/fish_indent.cpp index 61633dc10..01d3a3b94 100644 --- a/src/fish_indent.cpp +++ b/src/fish_indent.cpp @@ -23,7 +23,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA #include #include #include -#include +#include #include #include @@ -63,7 +63,7 @@ static wcstring read_file(FILE *f) { // Illegal byte sequence. Try to skip past it. clearerr(f); int ch = fgetc(f); // for printing the warning, and seeks forward 1 byte. - debug(1, "%s (byte=%X)", strerror(errno), ch); + debug(1, "%s (byte=%X)", std::strerror(errno), ch); ret = 1; continue; } else { @@ -518,7 +518,7 @@ int main(int argc, char *argv[]) { fclose(fh); output_location = *argv; } else { - std::fwprintf(stderr, _(L"Opening \"%s\" failed: %s\n"), *argv, strerror(errno)); + std::fwprintf(stderr, _(L"Opening \"%s\" failed: %s\n"), *argv, std::strerror(errno)); exit(1); } } else { @@ -549,7 +549,7 @@ int main(int argc, char *argv[]) { exit(0); } else { std::fwprintf(stderr, _(L"Opening \"%s\" failed: %s\n"), output_location, - strerror(errno)); + std::strerror(errno)); exit(1); } break; diff --git a/src/fish_key_reader.cpp b/src/fish_key_reader.cpp index fba073944..be845c63b 100644 --- a/src/fish_key_reader.cpp +++ b/src/fish_key_reader.cpp @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include #include #include @@ -62,7 +62,7 @@ static bool should_exit(wchar_t wc) { std::fwprintf(stderr, L"Press [ctrl-%c] again to exit\n", shell_modes.c_cc[VEOF] + 0x40); return false; } - return memcmp(recent_chars, "exit", 4) == 0 || memcmp(recent_chars, "quit", 4) == 0; + return std::memcmp(recent_chars, "exit", 4) == 0 || std::memcmp(recent_chars, "quit", 4) == 0; } /// Return the name if the recent sequence of characters matches a known terminfo sequence. @@ -265,7 +265,7 @@ static void install_our_signal_handlers() { for (int signo = 1; signo < 32; signo++) { if (sigaction(signo, &new_sa, &old_sa) != -1) { - memcpy(&old_sigactions[signo], &old_sa, sizeof(old_sa)); + std::memcpy(&old_sigactions[signo], &old_sa, sizeof(old_sa)); if (old_sa.sa_handler == SIG_IGN) { debug(3, "signal #%d (%ls) was being ignored", signo, sig2wcs(signo)); } diff --git a/src/fish_tests.cpp b/src/fish_tests.cpp index 9059cf101..e459dc504 100644 --- a/src/fish_tests.cpp +++ b/src/fish_tests.cpp @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include #include #include @@ -89,7 +89,7 @@ static bool should_test_function(const char *func_name) { result = true; } else { for (size_t i = 0; s_arguments[i] != NULL; i++) { - if (!strncmp(func_name, s_arguments[i], strlen(s_arguments[i]))) { + if (!std::strncmp(func_name, s_arguments[i], std::strlen(s_arguments[i]))) { // Prefix match. result = true; break; @@ -448,14 +448,14 @@ static void test_format() { for (i = 0; i < sizeof tests / sizeof *tests; i++) { char buff[128]; format_size_safe(buff, tests[i].val); - do_test(!strcmp(buff, tests[i].expected)); + do_test(!std::strcmp(buff, tests[i].expected)); } for (int j = -129; j <= 129; j++) { char buff1[128], buff2[128]; format_long_safe(buff1, j); sprintf(buff2, "%d", j); - do_test(!strcmp(buff1, buff2)); + do_test(!std::strcmp(buff1, buff2)); wchar_t wbuf1[128], wbuf2[128]; format_long_safe(wbuf1, j); @@ -467,12 +467,12 @@ static void test_format() { char buff1[128], buff2[128]; format_long_safe(buff1, q); sprintf(buff2, "%ld", q); - do_test(!strcmp(buff1, buff2)); + do_test(!std::strcmp(buff1, buff2)); } /// Helper to convert a narrow string to a sequence of hex digits. static char *str2hex(const char *input) { - char *output = (char *)malloc(5 * strlen(input) + 1); + char *output = (char *)malloc(5 * std::strlen(input) + 1); char *p = output; for (; *input; input++) { sprintf(p, "0x%02X ", (int)*input & 0xFF); @@ -511,12 +511,12 @@ static void test_convert() { L"wcs2str"); } - if (strcmp(o, n)) { + if (std::strcmp(o, n)) { char *o2 = str2hex(o); char *n2 = str2hex(n); err(L"Line %d - %d: Conversion cycle of string:\n%4d chars: %s\n" L"produced different string:\n%4d chars: %s", - __LINE__, i, strlen(o), o2, strlen(n), n2); + __LINE__, i, std::strlen(o), o2, std::strlen(n), n2); free(o2); free(n2); } @@ -1258,7 +1258,7 @@ static void test_utf82wchar(const char *src, size_t slen, const wchar_t *dst, si if (res != size) { err(L"u2w: %s: FAILED (rv: %lu, must be %lu)", descr, size, res); - } else if (mem && memcmp(mem, dst, size * sizeof(*mem)) != 0) { + } else if (mem && std::memcmp(mem, dst, size * sizeof(*mem)) != 0) { err(L"u2w: %s: BROKEN", descr); } @@ -1303,7 +1303,7 @@ static void test_wchar2utf8(const wchar_t *src, size_t slen, const char *dst, si size = wchar_to_utf8(src, slen, mem, dlen, flags); if (res != size) { err(L"w2u: %s: FAILED (rv: %lu, must be %lu)", descr, size, res); - } else if (dst && memcmp(mem, dst, size) != 0) { + } else if (dst && std::memcmp(mem, dst, size) != 0) { err(L"w2u: %s: BROKEN", descr); } @@ -1459,7 +1459,7 @@ static void test_escape_sequences() { err(L"test_escape_sequences failed on line %d\n", __LINE__); if (escape_code_length(L"\x1B[2J") != 4) err(L"test_escape_sequences failed on line %d\n", __LINE__); - if (escape_code_length(L"\x1B[38;5;123mABC") != strlen("\x1B[38;5;123m")) + if (escape_code_length(L"\x1B[38;5;123mABC") != std::strlen("\x1B[38;5;123m")) err(L"test_escape_sequences failed on line %d\n", __LINE__); if (escape_code_length(L"\x1B@") != 2) err(L"test_escape_sequences failed on line %d\n", __LINE__); @@ -3230,7 +3230,7 @@ static void test_universal_ok_to_save() { const char *contents = "# VERSION: 99999.99\n"; FILE *fp = wfopen(UVARS_TEST_PATH, "w"); assert(fp && "Failed to open UVARS_TEST_PATH for writing"); - fwrite(contents, strlen(contents), 1, fp); + fwrite(contents, std::strlen(contents), 1, fp); fclose(fp); file_id_t before_id = file_id_for_path(UVARS_TEST_PATH); @@ -5176,7 +5176,7 @@ int main(int argc, char **argv) { perror("getcwd"); exit(-1); } - if (!strcmp(wd, "/")) { + if (!std::strcmp(wd, "/")) { std::fwprintf(stderr, L"Unable to find 'tests' directory, which should contain file test.fish\n"); exit(EXIT_FAILURE); diff --git a/src/history.cpp b/src/history.cpp index 1c7abddfb..d0deb6eb5 100644 --- a/src/history.cpp +++ b/src/history.cpp @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include // We need the sys/file.h for the flock() declaration on Linux but not OS X. #include // IWYU pragma: keep @@ -75,10 +75,10 @@ static constexpr int max_save_tries = 1024; namespace { +static size_t safe_strlen(const char *s) { return s ? std::strlen(s) : 0; } /// Helper class for certain output. This is basically a string that allows us to ensure we only /// flush at record boundaries, and avoids the copying of ostringstream. Have you ever tried to /// implement your own streambuf? Total insanity. -static size_t safe_strlen(const char *s) { return s ? strlen(s) : 0; } class history_output_buffer_t { std::vector buffer; @@ -271,7 +271,7 @@ class history_file_contents_t { ptr += amt; } } - memset(ptr, 0, remaining); + std::memset(ptr, 0, remaining); return true; } @@ -350,7 +350,7 @@ static size_t read_line(const char *base, size_t cursor, size_t len, std::string // Locate the newline. assert(cursor <= len); const char *start = base + cursor; - const char *a_newline = (char *)memchr(start, '\n', len - cursor); + const char *a_newline = (char *)std::memchr(start, '\n', len - cursor); if (a_newline != NULL) { // we found a newline result.assign(start, a_newline - start); // Return the amount to advance the cursor; skip over the newline. @@ -513,7 +513,7 @@ static history_item_t decode_item_fish_2_0(const char *base, size_t len) { size_t advance = read_line(base, cursor, len, line); if (trim_leading_spaces(line) <= indent) break; - if (strncmp(line.c_str(), "- ", 2)) break; + if (std::strncmp(line.c_str(), "- ", 2)) break; // We're going to consume this line. cursor += advance; @@ -636,7 +636,7 @@ static bool parse_timestamp(const char *str, time_t *out_when) { // Look for "when:". size_t when_len = 5; - if (strncmp(cursor, "when:", when_len) != 0) return false; + if (std::strncmp(cursor, "when:", when_len) != 0) return false; cursor += when_len; // Advance past spaces. @@ -661,7 +661,7 @@ static const char *next_line(const char *start, size_t length) { const char *const end = start + length; // Skip past the next newline. - const char *nextline = (const char *)memchr(start, '\n', length); + const char *nextline = (const char *)std::memchr(start, '\n', length); if (!nextline || nextline >= end) { return NULL; } @@ -671,7 +671,7 @@ static const char *next_line(const char *start, size_t length) { } // Make sure this new line is itself "newline terminated". If it's not, return NULL. - const char *next_newline = (const char *)memchr(nextline, '\n', end - nextline); + const char *next_newline = (const char *)std::memchr(nextline, '\n', end - nextline); if (!next_newline) { return NULL; } @@ -694,7 +694,7 @@ static size_t offset_of_next_item_fish_2_0(const history_file_contents_t &conten const char *line_start = contents.address_at(cursor); // Advance the cursor to the next line. - const char *a_newline = (const char *)memchr(line_start, '\n', length - cursor); + const char *a_newline = (const char *)std::memchr(line_start, '\n', length - cursor); if (a_newline == NULL) break; // Advance the cursor past this line. +1 is for the newline. @@ -707,26 +707,26 @@ static size_t offset_of_next_item_fish_2_0(const history_file_contents_t &conten if (a_newline - line_start < 3) continue; // Try to be a little YAML compatible. Skip lines with leading %, ---, or ... - if (!memcmp(line_start, "%", 1) || !memcmp(line_start, "---", 3) || - !memcmp(line_start, "...", 3)) + if (!std::memcmp(line_start, "%", 1) || !std::memcmp(line_start, "---", 3) || + !std::memcmp(line_start, "...", 3)) continue; // Hackish: fish 1.x rewriting a fish 2.0 history file can produce lines with lots of // leading "- cmd: - cmd: - cmd:". Trim all but one leading "- cmd:". const char *double_cmd = "- cmd: - cmd: "; - const size_t double_cmd_len = strlen(double_cmd); + const size_t double_cmd_len = std::strlen(double_cmd); while ((size_t)(a_newline - line_start) > double_cmd_len && - !memcmp(line_start, double_cmd, double_cmd_len)) { + !std::memcmp(line_start, double_cmd, double_cmd_len)) { // Skip over just one of the - cmd. In the end there will be just one left. - line_start += strlen("- cmd: "); + line_start += std::strlen("- cmd: "); } // Hackish: fish 1.x rewriting a fish 2.0 history file can produce commands like "when: // 123456". Ignore those. const char *cmd_when = "- cmd: when:"; - const size_t cmd_when_len = strlen(cmd_when); + const size_t cmd_when_len = std::strlen(cmd_when); if ((size_t)(a_newline - line_start) >= cmd_when_len && - !memcmp(line_start, cmd_when, cmd_when_len)) { + !std::memcmp(line_start, cmd_when, cmd_when_len)) { continue; } @@ -1141,7 +1141,7 @@ wcstring history_search_t::current_string() const { } static void replace_all(std::string *str, const char *needle, const char *replacement) { - size_t needle_len = strlen(needle), replacement_len = strlen(replacement); + size_t needle_len = std::strlen(needle), replacement_len = std::strlen(replacement); size_t offset = 0; while ((offset = str->find(needle, offset)) != std::string::npos) { str->replace(offset, needle_len, replacement); @@ -1820,7 +1820,7 @@ void history_t::populate_from_bash(FILE *stream) { } // Deal with the newline if present. - char *a_newline = strchr(buff, '\n'); + char *a_newline = std::strchr(buff, '\n'); if (a_newline) *a_newline = '\0'; line.append(buff); if (a_newline) break; diff --git a/src/input_common.cpp b/src/input_common.cpp index 655f5dfc2..19e4356a3 100644 --- a/src/input_common.cpp +++ b/src/input_common.cpp @@ -2,7 +2,7 @@ #include "config.h" #include -#include +#include #include #ifdef HAVE_SYS_SELECT_H #include @@ -205,7 +205,7 @@ wchar_t input_common_readch(int timed) { switch (sz) { case (size_t)(-1): { - memset(&state, '\0', sizeof(state)); + std::memset(&state, '\0', sizeof(state)); debug(2, L"Illegal input"); return R_NULL; } diff --git a/src/io.cpp b/src/io.cpp index 5f2ed4166..727796c96 100644 --- a/src/io.cpp +++ b/src/io.cpp @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/iothread.cpp b/src/iothread.cpp index a9d799b43..d3f7220dc 100644 --- a/src/iothread.cpp +++ b/src/iothread.cpp @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/output.cpp b/src/output.cpp index 5cca74258..14d210c3c 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -3,7 +3,7 @@ #include #include -#include +#include #if HAVE_CURSES_H #include #elif HAVE_NCURSES_H @@ -234,7 +234,7 @@ void outputter_t::set_color(rgb_color_t c, rgb_color_t c2) { if (c == c2) c = (c2 == rgb_color_t::white()) ? rgb_color_t::black() : rgb_color_t::white(); } - if ((enter_bold_mode != 0) && (strlen(enter_bold_mode) > 0)) { + if ((enter_bold_mode != 0) && (std::strlen(enter_bold_mode) > 0)) { if (bg_set && !last_bg_set) { // Background color changed and is set, so we enter bold mode to make reading easier. // This means bold mode is _always_ on when the background color is set. @@ -295,7 +295,7 @@ void outputter_t::set_color(rgb_color_t c, rgb_color_t c2) { } // Lastly, we set bold, underline, italics, dim, and reverse modes correctly. - if (is_bold && !was_bold && enter_bold_mode && strlen(enter_bold_mode) > 0 && !bg_set) { + if (is_bold && !was_bold && enter_bold_mode && std::strlen(enter_bold_mode) > 0 && !bg_set) { // The unconst cast is for NetBSD's benefit. DO NOT REMOVE! writembs_nofail(*this, tparm((char *)enter_bold_mode)); was_bold = is_bold; @@ -310,27 +310,27 @@ void outputter_t::set_color(rgb_color_t c, rgb_color_t c2) { } was_underline = is_underline; - if (was_italics && !is_italics && enter_italics_mode && strlen(enter_italics_mode) > 0) { + if (was_italics && !is_italics && enter_italics_mode && std::strlen(enter_italics_mode) > 0) { writembs_nofail(*this, exit_italics_mode); was_italics = is_italics; } - if (!was_italics && is_italics && enter_italics_mode && strlen(enter_italics_mode) > 0) { + if (!was_italics && is_italics && enter_italics_mode && std::strlen(enter_italics_mode) > 0) { writembs_nofail(*this, enter_italics_mode); was_italics = is_italics; } - if (is_dim && !was_dim && enter_dim_mode && strlen(enter_dim_mode) > 0) { + if (is_dim && !was_dim && enter_dim_mode && std::strlen(enter_dim_mode) > 0) { writembs_nofail(*this, enter_dim_mode); was_dim = is_dim; } if (is_reverse && !was_reverse) { // Some terms do not have a reverse mode set, so standout mode is a fallback. - if (enter_reverse_mode && strlen(enter_reverse_mode) > 0) { + if (enter_reverse_mode && std::strlen(enter_reverse_mode) > 0) { writembs_nofail(*this, enter_reverse_mode); was_reverse = is_reverse; - } else if (enter_standout_mode && strlen(enter_standout_mode) > 0) { + } else if (enter_standout_mode && std::strlen(enter_standout_mode) > 0) { writembs_nofail(*this, enter_standout_mode); was_reverse = is_reverse; } diff --git a/src/output.h b/src/output.h index b0548aeb1..dee1ad982 100644 --- a/src/output.h +++ b/src/output.h @@ -69,7 +69,7 @@ class outputter_t { } /// Write a narrow NUL-terminated string. - void writestr(const char *str) { writestr(str, strlen(str)); } + void writestr(const char *str) { writestr(str, std::strlen(str)); } /// Write a narrow character. void push_back(char c) { diff --git a/src/path.cpp b/src/path.cpp index 2523e4ef9..93d941204 100644 --- a/src/path.cpp +++ b/src/path.cpp @@ -4,7 +4,7 @@ #include "config.h" // IWYU pragma: keep #include -#include +#include #include #include #include @@ -272,7 +272,7 @@ static void maybe_issue_path_warning(const wcstring &which_dir, const wcstring & const wchar_t *env_var = using_xdg ? xdg_var.c_str() : L"HOME"; debug(0, _(L"Unable to locate %ls directory derived from $%ls: '%ls'."), which_dir.c_str(), env_var, path.c_str()); - debug(0, _(L"The error was '%s'."), strerror(saved_errno)); + debug(0, _(L"The error was '%s'."), std::strerror(saved_errno)); debug(0, _(L"Please set $%ls to a directory where you have write access."), env_var); } ignore_result(write(STDERR_FILENO, "\n", 1)); diff --git a/src/postfork.cpp b/src/postfork.cpp index ca3607628..f4c14b6b6 100644 --- a/src/postfork.cpp +++ b/src/postfork.cpp @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include #include #if FISH_USE_POSIX_SPAWN @@ -308,11 +308,11 @@ void safe_report_exec_error(int err, const char *actual_cmd, const char *const * size_t sz = 0; const char *const *p; for (p = argv; *p; p++) { - sz += strlen(*p) + 1; + sz += std::strlen(*p) + 1; } for (p = envv; *p; p++) { - sz += strlen(*p) + 1; + sz += std::strlen(*p) + 1; } format_size_safe(sz1, sz); diff --git a/src/print_help.cpp b/src/print_help.cpp index c19a51dfc..db8ed074b 100644 --- a/src/print_help.cpp +++ b/src/print_help.cpp @@ -3,7 +3,7 @@ #include #include -#include +#include #include "common.h" #include "print_help.h" @@ -17,6 +17,6 @@ void print_help(const char *c, int fd) { int printed = snprintf(cmd, CMD_LEN, "fish -c '__fish_print_help %s >&%d'", c, fd); if (printed < CMD_LEN && system(cmd) == -1) { - write_loop(2, HELP_ERR, strlen(HELP_ERR)); + write_loop(2, HELP_ERR, std::strlen(HELP_ERR)); } } diff --git a/src/reader.cpp b/src/reader.cpp index 505dae066..0b8861633 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -23,7 +23,7 @@ #include #include #include -#include +#include #ifdef HAVE_SYS_SELECT_H #include #endif @@ -969,13 +969,13 @@ void reader_init() { tcgetattr(STDIN_FILENO, &terminal_mode_on_startup); // Set the mode used for program execution, initialized to the current mode. - memcpy(&tty_modes_for_external_cmds, &terminal_mode_on_startup, + std::memcpy(&tty_modes_for_external_cmds, &terminal_mode_on_startup, sizeof tty_modes_for_external_cmds); tty_modes_for_external_cmds.c_iflag &= ~IXON; // disable flow control tty_modes_for_external_cmds.c_iflag &= ~IXOFF; // disable flow control // Set the mode used for the terminal, initialized to the current mode. - memcpy(&shell_modes, &terminal_mode_on_startup, sizeof shell_modes); + std::memcpy(&shell_modes, &terminal_mode_on_startup, sizeof shell_modes); shell_modes.c_iflag &= ~ICRNL; // disable mapping CR (\cM) to NL (\cJ) shell_modes.c_iflag &= ~INLCR; // disable mapping NL (\cJ) to CR (\cM) @@ -2447,7 +2447,7 @@ maybe_t reader_data_t::readline(int nchars) { (size_t)READAHEAD_MAX) : READAHEAD_MAX; - memset(arr, 0, sizeof(arr)); + std::memset(arr, 0, sizeof(arr)); arr[0] = c; for (i = 1; i < limit; ++i) { diff --git a/src/screen.cpp b/src/screen.cpp index bc3161a40..30efe600f 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include #include @@ -460,7 +460,7 @@ static void s_move(screen_t *s, int new_x, int new_y) { y_steps = new_y - s->actual.cursor.y; - if (y_steps > 0 && (strcmp(cursor_down, "\n") == 0)) { + if (y_steps > 0 && (std::strcmp(cursor_down, "\n") == 0)) { // This is very strange - it seems some (all?) consoles use a simple newline as the cursor // down escape. This will of course move the cursor to the beginning of the line as well as // moving it down one step. The cursor_up does not have this behaviour... @@ -496,7 +496,7 @@ static void s_move(screen_t *s, int new_x, int new_y) { // Use the bulk ('multi') output for cursor movement if it is supported and it would be shorter // Note that this is required to avoid some visual glitches in iTerm (issue #1448). bool use_multi = - multi_str != NULL && multi_str[0] != '\0' && abs(x_steps) * strlen(str) > strlen(multi_str); + multi_str != NULL && multi_str[0] != '\0' && abs(x_steps) * std::strlen(str) > std::strlen(multi_str); if (use_multi && cur_term) { char *multi_param = tparm((char *)multi_str, abs(x_steps)); writembs(outp, multi_param); diff --git a/src/tinyexpr.cpp b/src/tinyexpr.cpp index 842219dea..e4ae70a34 100644 --- a/src/tinyexpr.cpp +++ b/src/tinyexpr.cpp @@ -26,7 +26,7 @@ #include "tinyexpr.h" #include #include -#include +#include #include #include @@ -96,9 +96,9 @@ static te_expr *new_expr(const int type, const te_expr *parameters[]) { te_expr *ret = (te_expr *)malloc(size); // This sets float to 0, which depends on the implementation. // We rely on IEEE-754 floats anyway, so it's okay. - memset(ret, 0, size); + std::memset(ret, 0, size); if (arity && parameters) { - memcpy(ret->parameters, parameters, psize); + std::memcpy(ret->parameters, parameters, psize); } ret->type = type; return ret; @@ -192,10 +192,10 @@ static const te_builtin *find_builtin(const char *name, int len) { const te_builtin *found = std::lower_bound(std::begin(functions), end, name, [len](const te_builtin &lhs, const char *rhs) { // The length is important because that's where the parens start - return strncmp(lhs.name, rhs, len) < 0; + return std::strncmp(lhs.name, rhs, len) < 0; }); // We need to compare again because we might have gotten the first "larger" element. - if (found != end && strncmp(found->name, name, len) == 0) return found; + if (found != end && std::strncmp(found->name, name, len) == 0) return found; return NULL; } diff --git a/src/wgetopt.cpp b/src/wgetopt.cpp index 2355db669..c39ccd730 100644 --- a/src/wgetopt.cpp +++ b/src/wgetopt.cpp @@ -40,7 +40,7 @@ #include #include -#include +#include // This version of `getopt' appears to the caller like standard Unix `getopt' but it behaves // differently for the user, since it allows the user to intersperse the options with the other diff --git a/src/wutil.cpp b/src/wutil.cpp index b9aefb108..2004dcf42 100644 --- a/src/wutil.cpp +++ b/src/wutil.cpp @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #if defined(__linux__) #include @@ -130,7 +130,7 @@ const wcstring wgetcwd() { return str2wcstring(res); } - debug(0, _(L"getcwd() failed with errno %d/%s"), errno, strerror(errno)); + debug(0, _(L"getcwd() failed with errno %d/%s"), errno, std::strerror(errno)); return wcstring(); } @@ -262,7 +262,7 @@ void wperror(const wchar_t *s) { if (s[0] != L'\0') { std::fwprintf(stderr, L"%ls: ", s); } - std::fwprintf(stderr, L"%s\n", strerror(e)); + std::fwprintf(stderr, L"%s\n", std::strerror(e)); } int make_fd_nonblocking(int fd) { @@ -318,7 +318,7 @@ int fd_check_is_remote(int fd) { } static inline void safe_append(char *buffer, const char *s, size_t buffsize) { - strncat(buffer, s, buffsize - strlen(buffer) - 1); + std::strncat(buffer, s, buffsize - std::strlen(buffer) - 1); } // In general, strerror is not async-safe, and therefore we cannot use it directly. So instead we @@ -328,7 +328,7 @@ const char *safe_strerror(int err) { #if defined(__UCLIBC__) // uClibc does not have sys_errlist, however, its strerror is believed to be async-safe. // See issue #808. - return strerror(err); + return std::strerror(err); #elif defined(HAVE__SYS__ERRS) || defined(HAVE_SYS_ERRLIST) #ifdef HAVE_SYS_ERRLIST if (err >= 0 && err < sys_nerr && sys_errlist[err] != NULL) { @@ -373,7 +373,7 @@ void safe_perror(const char *message) { safe_append(buff, safe_strerror(err), sizeof buff); safe_append(buff, "\n", sizeof buff); - ignore_result(write(STDERR_FILENO, buff, strlen(buff))); + ignore_result(write(STDERR_FILENO, buff, std::strlen(buff))); errno = err; } diff --git a/src/wutil.h b/src/wutil.h index 661e82d05..80eaf8005 100644 --- a/src/wutil.h +++ b/src/wutil.h @@ -59,7 +59,7 @@ void wperror(const wchar_t *s); /// Async-safe version of perror(). void safe_perror(const char *message); -/// Async-safe version of strerror(). +/// Async-safe version of std::strerror(). const char *safe_strerror(int err); /// Wide character version of getcwd().