tmpdir: Split out new file of common utilities.
authorMark Wooding <mdw@distorted.org.uk>
Sun, 13 Apr 2008 20:53:16 +0000 (21:53 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sun, 13 Apr 2008 20:53:16 +0000 (21:53 +0100)
In particular, the allowgroup function is wanted by both programs, but
it's too nasty to put in the library.

Makefile.am
tmpdir.c
utils.c [new file with mode: 0644]
utils.h [new file with mode: 0644]

index 42e907d..b23bcbc 100644 (file)
 
 bin_PROGRAMS            =
 lib_LTLIBRARIES                 =
+noinst_LIBRARIES        =
 include_HEADERS                 =
 dist_man_MANS           =
 
 CLEANFILES              =
 EXTRA_DIST              =
+LDADD                   =
+
+###--------------------------------------------------------------------------
+### Programs.
+
+## Common stuff.
+noinst_LIBRARIES       += libutils.a
+libutils_a_SOURCES      =
+LDADD                  += libutils.a
+
+libutils_a_SOURCES     += utils.c
+libutils_a_SOURCES     += utils.h
+
+## chkpath
+bin_PROGRAMS           += chkpath
+dist_man_MANS          += chkpath.1
+
+## tmpdir
+bin_PROGRAMS           += tmpdir
+dist_man_MANS          += tmpdir.1
 
 ###--------------------------------------------------------------------------
 ### Library.
@@ -40,6 +61,7 @@ libcheckpath_la_SOURCES        =
 libcheckpath_la_LDFLAGS         = -version-info $(LIBTOOL_VERSION_INFO)
 libcheckpath_la_LIBADD  = $(mLib_LIBS)
 dist_man_MANS          += checkpath.3
+LDADD                  += libcheckpath.la
 
 libcheckpath_la_SOURCES        += checkpath.c
 include_HEADERS                += checkpath.h
@@ -58,19 +80,6 @@ checkpath.pc: checkpath.pc.in Makefile
        mv $@.new $@
 
 ###--------------------------------------------------------------------------
-### Programs.
-
-LDADD                   = libcheckpath.la $(mLib_LIBS)
-
-## chkpath
-bin_PROGRAMS           += chkpath
-dist_man_MANS          += chkpath.1
-
-## tmpdir
-bin_PROGRAMS           += tmpdir
-dist_man_MANS          += tmpdir.1
-
-###--------------------------------------------------------------------------
 ### Other finishing touches.
 
 ## Version stamp.
@@ -80,6 +89,9 @@ dist-hook::
 ## Build tools.
 EXTRA_DIST             += config/confsubst
 
+## External libraries.
+LDADD                  += $(mLib_LIBS)
+
 ###--------------------------------------------------------------------------
 ### Debian.
 
index 466b29c..070dee0 100644 (file)
--- a/tmpdir.c
+++ b/tmpdir.c
@@ -48,6 +48,7 @@
 #include <mLib/report.h>
 
 #include "checkpath.h"
+#include "utils.h"
 
 /*----- Static variables --------------------------------------------------*/
 
@@ -272,46 +273,6 @@ setting for that shell type.\n\
        fp);
 }
 
-/* --- @allowgroup@ --- *
- *
- * Arguments:  @const char *gname@ = trust group @gname@
- *
- * Returns:    ---
- *
- * Use:                Adds the gid corresponding to @gname@ (which may be a number)
- *             to the list of things we trust.
- */
-
-static void allowgroup(const char *gname)
-{
-  struct group *gr;
-  const char *p;
-  gid_t g;
-
-  /* --- Check for numeric group spec --- */
-
-  for (p = gname; *p; p++) {
-    if (!isdigit((unsigned char)*p))
-      goto lookup;
-  }
-  g = atoi(gname);
-  goto insert;
-
-  /* --- Look up a group by name --- */
-
-lookup:
-  if ((gr = getgrnam(gname)) == 0)
-    die(1, "group %s not found", gname);
-  g = gr->gr_gid;
-
-  /* --- Insert the group into the table --- */
-
-insert:
-  if (cp.cp_gids >= N(cp.cp_gid))
-    die(1, "too many groups");
-  cp.cp_gid[cp.cp_gids++] = g;
-}
-
 /* --- @main@ --- *
  *
  * Arguments:  @int argc@ = number of command line arguments
@@ -387,7 +348,7 @@ int main(int argc, char *argv[])
        return (!fullcheck(optarg));
        break;
       case 'g':
-       allowgroup(optarg);
+       allowgroup(&cp, optarg);
        break;
       case 'v':
        cp.cp_verbose++;
diff --git a/utils.c b/utils.c
new file mode 100644 (file)
index 0000000..883a219
--- /dev/null
+++ b/utils.c
@@ -0,0 +1,86 @@
+/* -*-c-*-
+ *
+ * Utilities not worth librarifying
+ *
+ * (c) 2008 Mark Wooding
+ */
+
+/*----- Licensing notice --------------------------------------------------*
+ *
+ * This file is part of chkpath.
+ *
+ * chkpath is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * chkpath is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with chkpath; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+/*----- Header files ------------------------------------------------------*/
+
+#include "config.h"
+
+#include <ctype.h>
+
+#include <sys/types.h>
+
+#include <grp.h>
+
+#include <mLib/macros.h>
+#include <mLib/report.h>
+
+#include "checkpath.h"
+#include "utils.h"
+
+/*----- Main code ---------------------------------------------------------*/
+
+/* --- @allowgroup@ --- *
+ *
+ * Arguments:  @struct checkpath *cp@ = pointer to structure to mess with
+ *             @const char *gname@ = trust group @gname@
+ *
+ * Returns:    ---
+ *
+ * Use:                Adds the gid corresponding to @gname@ (which may be a number)
+ *             to the list of things we trust.
+ */
+
+void allowgroup(struct checkpath *cp, const char *gname)
+{
+  struct group *gr;
+  const char *p;
+  gid_t g;
+
+  /* --- Check for numeric group spec --- */
+
+  for (p = gname; *p; p++) {
+    if (!isdigit((unsigned char)*p))
+      goto lookup;
+  }
+  g = atoi(gname);
+  goto insert;
+
+  /* --- Look up a group by name --- */
+
+lookup:
+  if ((gr = getgrnam(gname)) == 0)
+    die(1, "group %s not found", gname);
+  g = gr->gr_gid;
+
+  /* --- Insert the group into the table --- */
+
+insert:
+  if (cp->cp_gids >= N(cp->cp_gid))
+    die(1, "too many groups");
+  cp->cp_gid[cp->cp_gids++] = g;
+}
+
+/*----- That's all, folks -------------------------------------------------*/
diff --git a/utils.h b/utils.h
new file mode 100644 (file)
index 0000000..fc29aee
--- /dev/null
+++ b/utils.h
@@ -0,0 +1,60 @@
+/* -*-c-*-
+ *
+ * Utilities not worth librarifying
+ *
+ * (c) 2008 Mark Wooding
+ */
+
+/*----- Licensing notice --------------------------------------------------*
+ *
+ * This file is part of chkpath.
+ *
+ * chkpath is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * chkpath is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with chkpath; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef UTILS_H
+#define UTILS_H
+
+#ifdef __cplusplus
+  extern "C" {
+#endif
+
+/*----- Header files ------------------------------------------------------*/
+
+#include "checkpath.h"
+
+/*----- Functions provided ------------------------------------------------*/
+
+/* --- @allowgroup@ --- *
+ *
+ * Arguments:  @struct checkpath *cp@ = pointer to structure to mess with
+ *             @const char *gname@ = trust group @gname@
+ *
+ *
+ * Returns:    ---
+ *
+ * Use:                Adds the gid corresponding to @gname@ (which may be a number)
+ *             to the list of things we trust.
+ */
+
+extern void allowgroup(struct checkpath */*cp*/, const char */*gname*/);
+
+/*----- That's all, folks -------------------------------------------------*/
+
+#ifdef __cplusplus
+  }
+#endif
+
+#endif