summaryrefslogtreecommitdiff
path: root/src/common.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/common.c')
-rw-r--r--src/common.c73
1 files changed, 12 insertions, 61 deletions
diff --git a/src/common.c b/src/common.c
index 800aea5..6bef268 100644
--- a/src/common.c
+++ b/src/common.c
@@ -505,33 +505,14 @@ str_remove_slice (struct str *self, size_t start, size_t length)
struct error
{
- size_t domain; ///< The domain of the error
- int id; ///< The concrete error ID
char *message; ///< Textual description of the event
};
-static size_t
-error_resolve_domain (size_t *tag)
-{
- // This method is fairly sensitive to the order in which resolution
- // requests come in, does not provide a good way of decoding the number
- // back to a meaningful identifier, and may not play all too well with
- // dynamic libraries when a module is e.g. statically linked into multiple
- // libraries, but it's fast, simple, and more than enough for our purposes.
- static size_t domain_counter;
-
- if (!*tag)
- *tag = ++domain_counter;
- return *tag;
-}
-
static void
-error_set (struct error **e, size_t domain, int id,
- const char *message, ...) ATTRIBUTE_PRINTF (4, 5);
+error_set (struct error **e, const char *message, ...) ATTRIBUTE_PRINTF (2, 3);
static void
-error_set (struct error **e, size_t domain, int id,
- const char *message, ...)
+error_set (struct error **e, const char *message, ...)
{
if (!e)
return;
@@ -544,8 +525,6 @@ error_set (struct error **e, size_t domain, int id,
hard_assert (size >= 0);
struct error *tmp = xmalloc (sizeof *tmp);
- tmp->domain = domain;
- tmp->id = id;
tmp->message = xmalloc (size + 1);
va_start (ap, message);
@@ -1438,14 +1417,6 @@ resolve_config_filename (const char *filename)
return result;
}
-static size_t io_error_domain_tag;
-#define IO_ERROR (error_resolve_domain (&io_error_domain_tag))
-
-enum
-{
- IO_ERROR_FAILED
-};
-
static bool
ensure_directory_existence (const char *path, struct error **e)
{
@@ -1455,16 +1426,14 @@ ensure_directory_existence (const char *path, struct error **e)
{
if (mkdir (path, S_IRWXU | S_IRWXG | S_IRWXO))
{
- error_set (e, IO_ERROR, IO_ERROR_FAILED,
- "cannot create directory `%s': %s",
+ error_set (e, "cannot create directory `%s': %s",
path, strerror (errno));
return false;
}
}
else if (!S_ISDIR (st.st_mode))
{
- error_set (e, IO_ERROR, IO_ERROR_FAILED,
- "cannot create directory `%s': %s",
+ error_set (e, "cannot create directory `%s': %s",
path, "file exists but is not a directory");
return false;
}
@@ -1574,14 +1543,6 @@ xssl_get_error (SSL *ssl, int result, const char **error_info)
// --- Regular expressions -----------------------------------------------------
-static size_t regex_error_domain_tag;
-#define REGEX_ERROR (error_resolve_domain (&regex_error_domain_tag))
-
-enum
-{
- REGEX_ERROR_COMPILATION_FAILED
-};
-
static regex_t *
regex_compile (const char *regex, int flags, struct error **e)
{
@@ -1599,8 +1560,7 @@ regex_compile (const char *regex, int flags, struct error **e)
desc.str + desc.len, desc.alloc - desc.len) - 1;
free (re);
- error_set (e, REGEX_ERROR, REGEX_ERROR_COMPILATION_FAILED,
- "%s: %s", "failed to compile regular expression", desc.str);
+ error_set (e, "%s: %s", "failed to compile regular expression", desc.str);
str_free (&desc);
return NULL;
}
@@ -1793,14 +1753,6 @@ irc_strcmp (const char *a, const char *b)
// The keys are stripped of surrounding whitespace, the values are not.
-static size_t config_error_domain_tag;
-#define CONFIG_ERROR (error_resolve_domain (&config_error_domain_tag))
-
-enum
-{
- CONFIG_ERROR_MALFORMED
-};
-
struct config_item
{
const char *key;
@@ -1828,8 +1780,8 @@ read_config_file (struct str_map *config, struct error **e)
FILE *fp = fopen (filename, "r");
if (!fp)
{
- error_set (e, IO_ERROR, IO_ERROR_FAILED,
- "could not open `%s' for reading: %s", filename, strerror (errno));
+ error_set (e, "could not open `%s' for reading: %s",
+ filename, strerror (errno));
return false;
}
@@ -1851,8 +1803,8 @@ read_config_file (struct str_map *config, struct error **e)
{
if (*start)
{
- error_set (e, CONFIG_ERROR, CONFIG_ERROR_MALFORMED,
- "line %u in config: %s", line_no, "malformed input");
+ error_set (e, "line %u in config: %s",
+ line_no, "malformed input");
errors = true;
break;
}
@@ -1907,8 +1859,8 @@ write_default_config (const char *filename, const char *prolog,
FILE *fp = fopen (path.str, "w");
if (!fp)
{
- error_set (e, IO_ERROR, IO_ERROR_FAILED,
- "could not open `%s' for writing: %s", path.str, strerror (errno));
+ error_set (e, "could not open `%s' for writing: %s",
+ path.str, strerror (errno));
goto error;
}
@@ -1927,8 +1879,7 @@ write_default_config (const char *filename, const char *prolog,
fclose (fp);
if (errno)
{
- error_set (e, IO_ERROR, IO_ERROR_FAILED,
- "writing to `%s' failed: %s", path.str, strerror (errno));
+ error_set (e, "writing to `%s' failed: %s", path.str, strerror (errno));
goto error;
}