Eliminate the `rlimits.h' header using scary macros.
[fwd] / fwd.h
diff --git a/fwd.h b/fwd.h
index 2d139e4..5868fda 100644 (file)
--- a/fwd.h
+++ b/fwd.h
   extern char **environ;
 #endif
 
+/*----- Resource limit names ----------------------------------------------*/
+
+#if defined(RLIMIT_OFILE) && !defined(RLIMIT_NOFILE)
+#  define RLIMIT_NOFILE RLIMIT_OFILE
+#endif
+
+/*
+   ;;; The resource-limit name table is very boring to type and less fun to
+   ;;; maintain.  To make life less awful, put the names in this list and
+   ;;; evaluate the code to get Emacs to regenerate it.
+
+   (let ((limits '(as core cpu data fsize locks memlock msgqueue
+                  nice nofile nproc rss rtprio sigpending stack
+                  vmem)))
+     (save-excursion
+       (goto-char
+       (point-min))
+       (search-forward (concat "***" "BEGIN rlimitlist" "***"))
+       (beginning-of-line 2)
+       (delete-region (point)
+                     (progn
+                       (search-forward "***END***")
+                       (beginning-of-line)
+                       (point)))
+       (let ((avail (make-marker))
+            (list (make-marker)))
+        (set-marker avail (point))
+        (insert "#define RLIMITS(_)")
+        (set-marker list (point))
+        (dolist (limit (sort (copy-list limits) #'string<))
+          (let* ((name (symbol-name limit))
+                 (constant (concat "RLIMIT_" (upcase name)))
+                 (have (concat "HAVE_" constant "_P")))
+            (goto-char avail)
+            (insert-before-markers (format (concat "#ifdef %s\n"
+                                                   "#  define %s t\n"
+                                                   "#else\n"
+                                                   "#  define %s nil\n"
+                                                   "#endif\n")
+                                           constant have have))
+            (goto-char list)
+            (insert-before-markers
+             (format " \\\n  MAYBE_ITEM(_, %s, (%s, %s))"
+                     have name constant))))
+        (goto-char list)
+        (insert "\n"))))
+*/
+
+/***BEGIN rlimitlist***/
+#ifdef RLIMIT_AS
+#  define HAVE_RLIMIT_AS_P t
+#else
+#  define HAVE_RLIMIT_AS_P nil
+#endif
+#ifdef RLIMIT_CORE
+#  define HAVE_RLIMIT_CORE_P t
+#else
+#  define HAVE_RLIMIT_CORE_P nil
+#endif
+#ifdef RLIMIT_CPU
+#  define HAVE_RLIMIT_CPU_P t
+#else
+#  define HAVE_RLIMIT_CPU_P nil
+#endif
+#ifdef RLIMIT_DATA
+#  define HAVE_RLIMIT_DATA_P t
+#else
+#  define HAVE_RLIMIT_DATA_P nil
+#endif
+#ifdef RLIMIT_FSIZE
+#  define HAVE_RLIMIT_FSIZE_P t
+#else
+#  define HAVE_RLIMIT_FSIZE_P nil
+#endif
+#ifdef RLIMIT_LOCKS
+#  define HAVE_RLIMIT_LOCKS_P t
+#else
+#  define HAVE_RLIMIT_LOCKS_P nil
+#endif
+#ifdef RLIMIT_MEMLOCK
+#  define HAVE_RLIMIT_MEMLOCK_P t
+#else
+#  define HAVE_RLIMIT_MEMLOCK_P nil
+#endif
+#ifdef RLIMIT_MSGQUEUE
+#  define HAVE_RLIMIT_MSGQUEUE_P t
+#else
+#  define HAVE_RLIMIT_MSGQUEUE_P nil
+#endif
+#ifdef RLIMIT_NICE
+#  define HAVE_RLIMIT_NICE_P t
+#else
+#  define HAVE_RLIMIT_NICE_P nil
+#endif
+#ifdef RLIMIT_NOFILE
+#  define HAVE_RLIMIT_NOFILE_P t
+#else
+#  define HAVE_RLIMIT_NOFILE_P nil
+#endif
+#ifdef RLIMIT_NPROC
+#  define HAVE_RLIMIT_NPROC_P t
+#else
+#  define HAVE_RLIMIT_NPROC_P nil
+#endif
+#ifdef RLIMIT_RSS
+#  define HAVE_RLIMIT_RSS_P t
+#else
+#  define HAVE_RLIMIT_RSS_P nil
+#endif
+#ifdef RLIMIT_RTPRIO
+#  define HAVE_RLIMIT_RTPRIO_P t
+#else
+#  define HAVE_RLIMIT_RTPRIO_P nil
+#endif
+#ifdef RLIMIT_SIGPENDING
+#  define HAVE_RLIMIT_SIGPENDING_P t
+#else
+#  define HAVE_RLIMIT_SIGPENDING_P nil
+#endif
+#ifdef RLIMIT_STACK
+#  define HAVE_RLIMIT_STACK_P t
+#else
+#  define HAVE_RLIMIT_STACK_P nil
+#endif
+#ifdef RLIMIT_VMEM
+#  define HAVE_RLIMIT_VMEM_P t
+#else
+#  define HAVE_RLIMIT_VMEM_P nil
+#endif
+#define RLIMITS(_) \
+  MAYBE_ITEM(_, HAVE_RLIMIT_AS_P, (as, RLIMIT_AS)) \
+  MAYBE_ITEM(_, HAVE_RLIMIT_CORE_P, (core, RLIMIT_CORE)) \
+  MAYBE_ITEM(_, HAVE_RLIMIT_CPU_P, (cpu, RLIMIT_CPU)) \
+  MAYBE_ITEM(_, HAVE_RLIMIT_DATA_P, (data, RLIMIT_DATA)) \
+  MAYBE_ITEM(_, HAVE_RLIMIT_FSIZE_P, (fsize, RLIMIT_FSIZE)) \
+  MAYBE_ITEM(_, HAVE_RLIMIT_LOCKS_P, (locks, RLIMIT_LOCKS)) \
+  MAYBE_ITEM(_, HAVE_RLIMIT_MEMLOCK_P, (memlock, RLIMIT_MEMLOCK)) \
+  MAYBE_ITEM(_, HAVE_RLIMIT_MSGQUEUE_P, (msgqueue, RLIMIT_MSGQUEUE)) \
+  MAYBE_ITEM(_, HAVE_RLIMIT_NICE_P, (nice, RLIMIT_NICE)) \
+  MAYBE_ITEM(_, HAVE_RLIMIT_NOFILE_P, (nofile, RLIMIT_NOFILE)) \
+  MAYBE_ITEM(_, HAVE_RLIMIT_NPROC_P, (nproc, RLIMIT_NPROC)) \
+  MAYBE_ITEM(_, HAVE_RLIMIT_RSS_P, (rss, RLIMIT_RSS)) \
+  MAYBE_ITEM(_, HAVE_RLIMIT_RTPRIO_P, (rtprio, RLIMIT_RTPRIO)) \
+  MAYBE_ITEM(_, HAVE_RLIMIT_SIGPENDING_P, (sigpending, RLIMIT_SIGPENDING)) \
+  MAYBE_ITEM(_, HAVE_RLIMIT_STACK_P, (stack, RLIMIT_STACK)) \
+  MAYBE_ITEM(_, HAVE_RLIMIT_VMEM_P, (vmem, RLIMIT_VMEM))
+/***END***/
+
+/* --- The unpleasant conditional-output machinery --- */
+
+#define MAYBE_ITEM(_, emitp, args) GLUE(MAYBE_ITEM_, emitp)(_, args)
+#define MAYBE_ITEM_t(_, args) _ args
+#define MAYBE_ITEM_nil(_, args)
+
 /*----- Main program ------------------------------------------------------*/
 
 /* --- The global select state --- */