]> diplodocus.org Git - nmh/blobdiff - h/mh.h
lock_file.c: close(2) file descriptor on failure, avoiding leak.
[nmh] / h / mh.h
diff --git a/h/mh.h b/h/mh.h
index 75812a3c6a1cb18477ce9f75bd6f88e7d743e693..069d9cbea09d508b2750f2e9be33aa0726a4bfb7 100644 (file)
--- a/h/mh.h
+++ b/h/mh.h
 #define DMAXFOLDER     4       /* typical number of digits             */
 #define MAXFOLDER   1000       /* message increment                    */
 
 #define DMAXFOLDER     4       /* typical number of digits             */
 #define MAXFOLDER   1000       /* message increment                    */
 
-/* non-zero exit(3) values indicating the number of errors need to be
- * capped else they interfere with the shell's use of high seven-bit
- * values, and the shell's mapping of signals onto top-bit-set values.
- * Plus, every so often the eight-bit value will wrap to zero, wrongly
- * indicating success. */
-#define MAX_EXIT 120
-
 /*
  * This macro is for use by scan, for example, so that platforms with
  * a small BUFSIZ can easily allocate larger buffers.
  */
 #define NMH_BUFSIZ  max(BUFSIZ, 8192)
 
 /*
  * This macro is for use by scan, for example, so that platforms with
  * a small BUFSIZ can easily allocate larger buffers.
  */
 #define NMH_BUFSIZ  max(BUFSIZ, 8192)
 
-#ifndef FALSE
-#define FALSE false
-#endif
-#ifndef TRUE
-#define TRUE true
-#endif
-typedef unsigned char  boolean;  /* not int so we can pack in a structure */
-
 /* If we're using gcc then tell it extra information so it can do more
  * compile-time checks. */
 #if __GNUC__ > 2
 #define NORETURN __attribute__((__noreturn__))
 /* If we're using gcc then tell it extra information so it can do more
  * compile-time checks. */
 #if __GNUC__ > 2
 #define NORETURN __attribute__((__noreturn__))
-#define CHECK_PRINTF(fmt, arg) __attribute__((format(printf, fmt, arg)))
-#define ALLOC_SIZE(...) __attribute__((alloc_size(__VA_ARGS__)))
 #define CONST __attribute__((const))
 #define MALLOC __attribute__((malloc))
 #define NONNULL(...) __attribute__((nonnull(__VA_ARGS__)))
 #define CONST __attribute__((const))
 #define MALLOC __attribute__((malloc))
 #define NONNULL(...) __attribute__((nonnull(__VA_ARGS__)))
-#define NMH_UNUSED(i) (void) i
+#define PURE __attribute__((pure))
+#define ENDNULL __attribute__((sentinel))
 #else
 #define NORETURN
 #define CHECK_PRINTF(fmt, arg)
 #else
 #define NORETURN
 #define CHECK_PRINTF(fmt, arg)
@@ -54,9 +38,21 @@ typedef unsigned char  boolean;  /* not int so we can pack in a structure */
 #define CONST
 #define MALLOC
 #define NONNULL(...)
 #define CONST
 #define MALLOC
 #define NONNULL(...)
-#define NMH_UNUSED(i) i
+#define PURE
+#define ENDNULL
 #endif
 
 #endif
 
+#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
+#define ALLOC_SIZE(...) __attribute__((alloc_size(__VA_ARGS__)))
+#define CHECK_PRINTF(fmt, arg) __attribute__((format(printf, fmt, arg)))
+#else
+#define ALLOC_SIZE(...)
+#define CHECK_PRINTF(fmt, arg)
+#endif
+
+/* Silence the compiler's "unused variable" warning. */
+#define NMH_UNUSED(i) (void)i
+
 /* DIM gives the number of elements in the one-dimensional array a. */
 #define DIM(a) (sizeof (a) / sizeof (*(a)))
 
 /* DIM gives the number of elements in the one-dimensional array a. */
 #define DIM(a) (sizeof (a) / sizeof (*(a)))
 
@@ -67,6 +63,9 @@ typedef unsigned char  boolean;  /* not int so we can pack in a structure */
 /* FENDNULL fends off NULL by giving an empty string instead. */
 #define FENDNULL(s) ((s) ? (s) : "")
 
 /* FENDNULL fends off NULL by giving an empty string instead. */
 #define FENDNULL(s) ((s) ? (s) : "")
 
+/* If not specified in a file and PAGER is NULL or empty. */
+#define DEFAULT_PAGER "more"
+
 /*
  * char array that keeps track of size in both bytes and characters
  * Usage note:
 /*
  * char array that keeps track of size in both bytes and characters
  * Usage note:
@@ -91,8 +90,8 @@ void charstring_clear (charstring_t) NONNULL(1);
 const char *charstring_buffer (const charstring_t) NONNULL(1);
 /* User is responsible for free'ing result of buffer copy. */
 char *charstring_buffer_copy (const charstring_t) NONNULL(1);
 const char *charstring_buffer (const charstring_t) NONNULL(1);
 /* User is responsible for free'ing result of buffer copy. */
 char *charstring_buffer_copy (const charstring_t) NONNULL(1);
-size_t charstring_bytes (const charstring_t) NONNULL(1);
-size_t charstring_chars (const charstring_t) NONNULL(1);
+size_t charstring_bytes (const charstring_t) NONNULL(1) PURE;
+size_t charstring_chars (const charstring_t) NONNULL(1) PURE;
 /* Length of the last character in the charstring. */
 int charstring_last_char_len (const charstring_t) NONNULL(1);
 
 /* Length of the last character in the charstring. */
 int charstring_last_char_len (const charstring_t) NONNULL(1);
 
@@ -225,8 +224,8 @@ void bvector_fini(struct bvector *bv) NONNULL(1);
 void bvector_clear (bvector_t, size_t) NONNULL(1);
 void bvector_clear_all (bvector_t) NONNULL(1);
 void bvector_set (bvector_t, size_t) NONNULL(1);
 void bvector_clear (bvector_t, size_t) NONNULL(1);
 void bvector_clear_all (bvector_t) NONNULL(1);
 void bvector_set (bvector_t, size_t) NONNULL(1);
-unsigned int bvector_at (bvector_t, size_t) NONNULL(1);
-unsigned long bvector_first_bits (bvector_t) NONNULL(1);
+unsigned int bvector_at (bvector_t, size_t) NONNULL(1) PURE;
+unsigned long bvector_first_bits (bvector_t) NONNULL(1) PURE;
 
 typedef struct svector *svector_t;
 
 
 typedef struct svector *svector_t;
 
@@ -234,9 +233,9 @@ svector_t svector_create (size_t);
 void svector_free (svector_t) NONNULL(1);
 char *svector_push_back (svector_t, char *) NONNULL(1);
 char *svector_at (svector_t, size_t) NONNULL(1);
 void svector_free (svector_t) NONNULL(1);
 char *svector_push_back (svector_t, char *) NONNULL(1);
 char *svector_at (svector_t, size_t) NONNULL(1);
-char **svector_find(svector_t, const char *) NONNULL(1);
-char **svector_strs (svector_t) NONNULL(1);
-size_t svector_size (svector_t) NONNULL(1);
+char **svector_find(svector_t, const char *) NONNULL(1) PURE;
+char **svector_strs (svector_t) NONNULL(1) PURE;
+size_t svector_size (svector_t) NONNULL(1) PURE;
 
 typedef struct ivector *ivector_t;
 
 
 typedef struct ivector *ivector_t;