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
This commit is contained in:
Dirk-Jan C. Binnema
2021-07-28 23:58:55 +03:00
parent 71b9c7f598
commit c8a2151cb9
13 changed files with 35 additions and 35 deletions

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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",

View File

@ -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();
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}