chiark / gitweb /
disorder.h: more consistent approach to function attributes
[disorder] / lib / queue.c
index 0f39b23800fa5c31991fda8e7b21fb9ecdbc4842..c592f5a13a4e949f516e7106550dcf014720ac70 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * This file is part of DisOrder.
- * Copyright (C) 2004-2009 Richard Kettlewell
+ * Copyright (C) 2004-2009, 2011, 2013 Richard Kettlewell
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -77,8 +77,9 @@ static int unmarshall_long(char *data, struct queue_entry *q,
                           size_t offset,
                           void (*error_handler)(const char *, void *),
                           void *u) {
+  char errbuf[1024];
   if(xstrtol(&VALUE(q, offset, long), data, 0, 0)) {
-    error_handler(strerror(errno), u);
+    error_handler(format_error(ec_errno, errno, errbuf, sizeof errbuf), u);
     return -1;
   }
   return 0;
@@ -123,9 +124,10 @@ static int unmarshall_time_t(char *data, struct queue_entry *q,
                             void (*error_handler)(const char *, void *),
                             void *u) {
   long_long ul;
+  char errbuf[1024];
 
   if(xstrtoll(&ul, data, 0, 0)) {
-    error_handler(strerror(errno), u);
+    error_handler(format_error(ec_errno, errno, errbuf, sizeof errbuf), u);
     return -1;
   }
   VALUE(q, offset, time_t) = ul;
@@ -194,13 +196,23 @@ static const char *marshall_origin(const struct queue_entry *q, size_t offset) {
 
 #define F(n, h) { #n, offsetof(struct queue_entry, n), marshall_##h, unmarshall_##h, free_##h }
 
-static const struct field {
+/** @brief A field in a @ref queue_entry */
+static const struct queue_field {
+  /** @brief Field name */
   const char *name;
+
+  /** @brief Offset of value in @ref queue_entry structure */
   size_t offset;
+
+  /** @brief Marshaling function */
   const char *(*marshall)(const struct queue_entry *q, size_t offset);
+
+  /** @brief Unmarshaling function */
   int (*unmarshall)(char *data, struct queue_entry *q, size_t offset,
                    void (*error_handler)(const char *, void *),
                    void *u);
+
+  /** @brief Destructor */
   void (*free)(struct queue_entry *q, size_t offset);
 } fields[] = {
   /* Keep this table sorted. */
@@ -222,12 +234,12 @@ int queue_unmarshall(struct queue_entry *q, const char *s,
                     void (*error_handler)(const char *, void *),
                     void *u) {
   char **vec;
-  int nvec;
+  int nvec, rc;
 
   q->pid = -1;                          /* =none */
   if(!(vec = split(s, &nvec, SPLIT_QUOTES, error_handler, u)))
     return -1;
-  int rc = queue_unmarshall_vec(q, nvec, vec, error_handler, u);
+  rc = queue_unmarshall_vec(q, nvec, vec, error_handler, u);
   free_strings(nvec, vec);
   return rc;
 }
@@ -279,11 +291,12 @@ char *queue_marshall(const struct queue_entry *q) {
 }
 
 void queue_free(struct queue_entry *q, int rest) {
+  unsigned n;
   if(!q)
     return;
   if(rest)
     queue_free(q->next, rest);
-  for(unsigned n = 0; n < NFIELDS; ++n)
+  for(n = 0; n < NFIELDS; ++n)
     fields[n].free(q, fields[n].offset);
   xfree(q);
 }