From c8a2151cb9b8035f56d1e3301d9e6b2cf99a146e Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Wed, 28 Jul 2021 23:58:55 +0300 Subject: [PATCH] mu: use g_strerror instead of strerror Some #includes were missing for the latter (but only noticeable on some systems - e.g., build breaks on Cygwin). So let's replace with something that works equally everywhere. Fixes: #2060 --- contrib/gmime-test.c | 2 +- lib/index/mu-indexer.cc | 2 +- lib/index/mu-scanner.cc | 10 +++++----- lib/mu-maildir.cc | 14 +++++++------- lib/mu-msg-file.cc | 6 +++--- lib/mu-msg-part.cc | 6 +++--- lib/mu-script.cc | 4 ++-- lib/mu-server.cc | 2 +- lib/utils/mu-logger.cc | 4 ++-- lib/utils/mu-util.c | 12 ++++++------ mu/mu-cmd-index.cc | 4 ++-- mu/mu-cmd.cc | 2 +- mu/test-mu-cmd.cc | 2 +- 13 files changed, 35 insertions(+), 35 deletions(-) diff --git a/contrib/gmime-test.c b/contrib/gmime-test.c index 5c59ed2b..a443f35f 100644 --- a/contrib/gmime-test.c +++ b/contrib/gmime-test.c @@ -229,7 +229,7 @@ test_file (const char *path) file = fopen (path, "r"); if (!file) { g_warning ("cannot open file '%s': %s", path, - strerror(errno)); + g_strerror(errno)); rv = FALSE; goto leave; } diff --git a/lib/index/mu-indexer.cc b/lib/index/mu-indexer.cc index 09766081..b44567e1 100644 --- a/lib/index/mu-indexer.cc +++ b/lib/index/mu-indexer.cc @@ -338,7 +338,7 @@ Indexer::start(const Indexer::Config& conf) { const auto mdir{priv_->store_.metadata().root_maildir}; if (G_UNLIKELY(access (mdir.c_str(), R_OK) != 0)) { - g_critical("'%s' is not readable: %s", mdir.c_str(), strerror (errno)); + g_critical("'%s' is not readable: %s", mdir.c_str(), g_strerror (errno)); return false; } diff --git a/lib/index/mu-scanner.cc b/lib/index/mu-scanner.cc index 518eec91..65746ea9 100644 --- a/lib/index/mu-scanner.cc +++ b/lib/index/mu-scanner.cc @@ -91,7 +91,7 @@ Scanner::Private::process_dentry (const std::string& path, struct dirent *dentry const auto fullpath{path + "/" + dentry->d_name}; struct stat statbuf; if (::stat(fullpath.c_str(), &statbuf) != 0) { - g_warning ("failed to stat %s: %s", fullpath.c_str(), ::strerror(errno)); + g_warning ("failed to stat %s: %s", fullpath.c_str(), g_strerror(errno)); return false; } @@ -120,7 +120,7 @@ Scanner::Private::process_dir (const std::string& path, bool is_maildir) { const auto dir = opendir (path.c_str()); if (G_UNLIKELY(!dir)) { - g_warning("failed to scan dir %s: %s", path.c_str(), strerror(errno)); + g_warning("failed to scan dir %s: %s", path.c_str(), g_strerror(errno)); return false; } @@ -137,7 +137,7 @@ Scanner::Private::process_dir (const std::string& path, bool is_maildir) } if (errno != 0) { - g_warning("failed to read %s: %s", path.c_str(), strerror(errno)); + g_warning("failed to read %s: %s", path.c_str(), g_strerror(errno)); continue; } @@ -159,13 +159,13 @@ Scanner::Private::start() const auto mode{F_OK | R_OK}; if (G_UNLIKELY(access (path.c_str(), mode) != 0)) { - g_warning("'%s' is not readable: %s", path.c_str(), strerror (errno)); + g_warning("'%s' is not readable: %s", path.c_str(), g_strerror (errno)); return false; } struct stat statbuf{}; if (G_UNLIKELY(stat (path.c_str(), &statbuf) != 0)) { - g_warning("'%s' is not stat'able: %s", path.c_str(), strerror (errno)); + g_warning("'%s' is not stat'able: %s", path.c_str(), g_strerror (errno)); return false; } diff --git a/lib/mu-maildir.cc b/lib/mu-maildir.cc index f50381f2..47fb0e87 100644 --- a/lib/mu-maildir.cc +++ b/lib/mu-maildir.cc @@ -89,7 +89,7 @@ create_maildir (const char *path, mode_t mode, GError **err) return mu_util_g_set_error (err,MU_ERROR_FILE_CANNOT_MKDIR, "creating dir failed for %s: %s", - fullpath, strerror (errno)); + fullpath, g_strerror (errno)); } return TRUE; @@ -112,7 +112,7 @@ create_noindex (const char *path, GError **err) if (fd < 0 || close (fd) != 0) return mu_util_g_set_error (err, MU_ERROR_FILE_CANNOT_CREATE, "error in create_noindex: %s", - strerror (errno)); + g_strerror (errno)); return TRUE; } @@ -200,7 +200,7 @@ Mu::mu_maildir_link (const char* src, const char *targetpath, GError **err) if (rv != 0) mu_util_g_set_error (err, MU_ERROR_FILE_CANNOT_LINK, "error creating link %s => %s: %s", - targetfullpath, src, strerror (errno)); + targetfullpath, src, g_strerror (errno)); g_free (targetfullpath); return rv == 0 ? TRUE: FALSE; @@ -266,7 +266,7 @@ clear_links (const char *path, DIR *dir) if (d_type == DT_LNK) { if (unlink (fullpath) != 0 ) { g_warning ("error unlinking %s: %s", - fullpath, strerror(errno)); + fullpath, g_strerror(errno)); rv = FALSE; } } else if (d_type == DT_DIR) { @@ -274,7 +274,7 @@ clear_links (const char *path, DIR *dir) subdir = opendir (fullpath); if (!subdir) { g_warning ("failed to open dir %s: %s", - fullpath, strerror(errno)); + fullpath, g_strerror(errno)); rv = FALSE; goto next; } @@ -303,7 +303,7 @@ Mu::mu_maildir_clear_links (const char *path, GError **err) dir = opendir (path); if (!dir) { g_set_error (err, MU_ERROR_DOMAIN, MU_ERROR_FILE_CANNOT_OPEN, - "failed to open %s: %s", path, strerror(errno)); + "failed to open %s: %s", path, g_strerror(errno)); return FALSE; } @@ -507,7 +507,7 @@ get_file_size (const char* path) rv = stat (path, &statbuf); if (rv != 0) { - /* g_warning ("error: %s", strerror (errno)); */ + /* g_warning ("error: %s", g_strerror (errno)); */ return -1; } diff --git a/lib/mu-msg-file.cc b/lib/mu-msg-file.cc index d4c9482f..efa0bba1 100644 --- a/lib/mu-msg-file.cc +++ b/lib/mu-msg-file.cc @@ -92,14 +92,14 @@ init_file_metadata (MuMsgFile *self, const char* path, const gchar* mdir, if (access (path, R_OK) != 0) { mu_util_g_set_error (err, MU_ERROR_FILE, "cannot read file %s: %s", - path, strerror(errno)); + path, g_strerror(errno)); return FALSE; } if (stat (path, &statbuf) < 0) { mu_util_g_set_error (err, MU_ERROR_FILE, "cannot stat %s: %s", - path, strerror(errno)); + path, g_strerror(errno)); return FALSE; } @@ -151,7 +151,7 @@ get_mime_stream (MuMsgFile *self, const char *path, GError **err) if (!file) { g_set_error (err, MU_ERROR_DOMAIN, MU_ERROR_FILE, "cannot open %s: %s", - path, strerror (errno)); + path, g_strerror (errno)); return NULL; } diff --git a/lib/mu-msg-part.cc b/lib/mu-msg-part.cc index 47235870..77724a9f 100644 --- a/lib/mu-msg-part.cc +++ b/lib/mu-msg-part.cc @@ -739,7 +739,7 @@ write_object_to_fd (GMimeObject *obj, int fd, GError **err) if (write (fd, str, strlen(str)) == -1) { g_set_error (err, MU_ERROR_DOMAIN, MU_ERROR_GMIME, "failed to write object: %s", - strerror(errno)); + g_strerror(errno)); return FALSE; } @@ -768,7 +768,7 @@ save_object (GMimeObject *obj, MuMsgOptions opts, const char *fullpath, if (fd == -1) { g_set_error (err, MU_ERROR_DOMAIN, MU_ERROR_FILE, "could not open '%s' for writing: %s", - fullpath, errno ? strerror(errno) : "error"); + fullpath, errno ? g_strerror(errno) : "error"); return FALSE; } @@ -780,7 +780,7 @@ save_object (GMimeObject *obj, MuMsgOptions opts, const char *fullpath, if (close (fd) != 0 && !err) { /* don't write on top of old err */ g_set_error (err, MU_ERROR_DOMAIN, MU_ERROR_FILE, "could not close '%s': %s", - fullpath, errno ? strerror(errno) : "error"); + fullpath, errno ? g_strerror(errno) : "error"); return FALSE; } diff --git a/lib/mu-script.cc b/lib/mu-script.cc index 76af89c0..afcfd8e4 100644 --- a/lib/mu-script.cc +++ b/lib/mu-script.cc @@ -250,7 +250,7 @@ mu_script_get_script_info_list (const char *path, const char *ext, if (!dir) { mu_util_g_set_error (err, MU_ERROR_FILE_CANNOT_OPEN, "failed to open '%s': %s", - path, strerror(errno)); + path, g_strerror(errno)); return NULL; } @@ -323,7 +323,7 @@ mu_script_guile_run (MuScriptInfo *msi, const char *muhome, if (access (mu_script_info_path (msi), R_OK) != 0) { mu_util_g_set_error (err, MU_ERROR_FILE_CANNOT_READ, "failed to read script: %s", - strerror(errno)); + g_strerror(errno)); return FALSE; } diff --git a/lib/mu-server.cc b/lib/mu-server.cc index e418f667..fbac18a8 100644 --- a/lib/mu-server.cc +++ b/lib/mu-server.cc @@ -1097,7 +1097,7 @@ Server::Private::remove_handler (const Parameters& params) if (::unlink (path.c_str()) != 0 && errno != ENOENT) throw Error(Error::Code::File, "could not delete %s: %s", - path.c_str(), strerror (errno)); + path.c_str(), g_strerror (errno)); if (!store().remove_message (path)) g_warning("failed to remove message @ %s (%d) from store", diff --git a/lib/utils/mu-logger.cc b/lib/utils/mu-logger.cc index 75175277..01893891 100644 --- a/lib/utils/mu-logger.cc +++ b/lib/utils/mu-logger.cc @@ -48,7 +48,7 @@ maybe_open_logfile () MuStream.open (MuLogPath, std::ios::out | std::ios::app ); if (!MuStream.is_open()) { std::cerr << "opening " << MuLogPath << " failed:" - << strerror(errno) << std::endl; + << g_strerror(errno) << std::endl; return false; } @@ -78,7 +78,7 @@ maybe_rotate_logfile () if (g_rename(MuLogPath.c_str(), old.c_str()) != 0) std::cerr << "failed to rename " << MuLogPath << " -> " << old.c_str() - << ": " << ::strerror(errno) << std::endl; + << ": " << g_strerror(errno) << std::endl; return maybe_open_logfile(); } diff --git a/lib/utils/mu-util.c b/lib/utils/mu-util.c index 816a70ca..1742be61 100644 --- a/lib/utils/mu-util.c +++ b/lib/utils/mu-util.c @@ -110,7 +110,7 @@ mu_util_dir_expand (const char *path) /* now resolve any symlinks, .. etc. */ if (realpath (dir, resolved) == NULL) { /* g_debug ("%s: could not get realpath for '%s': %s", */ - /* __func__, dir, strerror(errno)); */ + /* __func__, dir, g_strerror(errno)); */ g_free (dir); return NULL; } else @@ -157,12 +157,12 @@ mu_util_check_dir (const gchar* path, gboolean readable, gboolean writeable) mode = F_OK | (readable ? R_OK : 0) | (writeable ? W_OK : 0); if (access (path, mode) != 0) { - /* g_debug ("Cannot access %s: %s", path, strerror (errno)); */ + /* g_debug ("Cannot access %s: %s", path, g_strerror (errno)); */ return FALSE; } if (stat (path, &statbuf) != 0) { - /* g_debug ("Cannot stat %s: %s", path, strerror (errno)); */ + /* g_debug ("Cannot stat %s: %s", path, g_strerror (errno)); */ return FALSE; } @@ -217,7 +217,7 @@ mu_util_create_dir_maybe (const gchar *path, mode_t mode, gboolean nowarn) if (g_mkdir_with_parents (path, mode) != 0) { if (!nowarn) g_warning ("failed to create %s: %s", - path, strerror(errno)); + path, g_strerror(errno)); return FALSE; } @@ -355,7 +355,7 @@ mu_util_get_dtype (const char *path, gboolean use_lstat) if (res != 0) { g_warning ("%sstat failed on %s: %s", - use_lstat ? "l" : "", path, strerror(errno)); + use_lstat ? "l" : "", path, g_strerror(errno)); return DT_UNKNOWN; } @@ -496,7 +496,7 @@ mu_util_read_password (const char *prompt) pass = getpass (prompt); /* returns static mem, don't free */ if (!pass) { if (errno) - g_warning ("error: %s", strerror(errno)); + g_warning ("error: %s", g_strerror(errno)); return NULL; } diff --git a/mu/mu-cmd-index.cc b/mu/mu-cmd-index.cc index 53665cde..49429fe0 100644 --- a/mu/mu-cmd-index.cc +++ b/mu/mu-cmd-index.cc @@ -59,7 +59,7 @@ install_sig_handler (void) for (i = 0; i != G_N_ELEMENTS(sigs); ++i) if (sigaction (sigs[i], &action, NULL) != 0) g_critical ("set sigaction for %d failed: %s", - sigs[i], strerror (errno));; + sigs[i], g_strerror (errno));; } @@ -101,7 +101,7 @@ Mu::mu_cmd_index (Mu::Store& store, const MuConfig *opts, GError **err) const auto mdir{store.metadata().root_maildir}; if (G_UNLIKELY(access (mdir.c_str(), R_OK) != 0)) { mu_util_g_set_error(err, MU_ERROR_FILE, - "'%s' is not readable: %s", mdir.c_str(), strerror (errno)); + "'%s' is not readable: %s", mdir.c_str(), g_strerror (errno)); return MU_ERROR; } diff --git a/mu/mu-cmd.cc b/mu/mu-cmd.cc index b0054596..49891bb2 100644 --- a/mu/mu-cmd.cc +++ b/mu/mu-cmd.cc @@ -308,7 +308,7 @@ check_file_okay (const char *path, gboolean cmd_add) if (cmd_add && access(path, R_OK) != 0) { g_printerr ("path is not readable: %s: %s\n", - path, strerror (errno)); + path, g_strerror (errno)); return FALSE; } diff --git a/mu/test-mu-cmd.cc b/mu/test-mu-cmd.cc index b137c1fe..25e647c3 100644 --- a/mu/test-mu-cmd.cc +++ b/mu/test-mu-cmd.cc @@ -371,7 +371,7 @@ get_file_size (const char* path) rv = stat (path, &statbuf); if (rv != 0) { - /* g_warning ("error: %s", strerror (errno)); */ + /* g_warning ("error: %s", g_strerror (errno)); */ return -1; }