summaryrefslogtreecommitdiff
path: root/src/common.c
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2014-07-15 22:54:39 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2014-07-16 00:53:59 +0200
commit2921eed702d994352c5afccc31e32bd3f1682b6b (patch)
tree044ef2300088f723d627ab529d7c052a84f74b48 /src/common.c
parenta2a979ea2e7ded82cbe4d4cab5da6e613d74a9d0 (diff)
downloadxK-2921eed702d994352c5afccc31e32bd3f1682b6b.tar.gz
xK-2921eed702d994352c5afccc31e32bd3f1682b6b.tar.xz
xK-2921eed702d994352c5afccc31e32bd3f1682b6b.zip
Rip out error codes
As it turns out, they're rather annoying to maintain, and we don't even need them. They also clutter the code unnecessarily in their current form. If it ever comes to having to have them, let's make another version of error_set(), maybe error_set_with_code(), that makes it possible to also set an integer within `struct error'. The only problem with the above solution is when we aggregate errors from multiple functions (be it by calling one after another, or through nesting of functions that may return an error). But let's care about that when the time comes for it.
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;
}