]> code.citadel.org Git - citadel.git/blobdiff - citadel/aidepost.c
fix build for Solaris
[citadel.git] / citadel / aidepost.c
index 81fbe7784328ba00395118745f36c518d3591777..3591ff8962fbd33c107050afafbbf27fc96f2c28 100644 (file)
@@ -7,14 +7,33 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <stdio.h>
-#include <time.h>
+
+#if TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# if HAVE_SYS_TIME_H
+#  include <sys/time.h>
+# else
+#  include <time.h>
+# endif
+#endif
+
 #include <limits.h>
 #include <errno.h>
 #include <string.h>
 #include "citadel.h"
 #include "config.h"
 
-void make_message(FILE *fp, char *target_room, char *author)
+#ifndef HAVE_SNPRINTF
+#include "snprintf.h"
+#endif
+
+
+/*
+ * Simplified function to generate a message in our format
+ */
+static void ap_make_message(FILE *fp, char *target_room, char *author)
 {
        int a;
        long bb, cc;
@@ -78,18 +97,21 @@ int main(int argc, char **argv)
                }
        }
 
+       snprintf(tempspool, sizeof tempspool,
+               "./network/spoolin/ap.%04lx",
+               (long)getpid());
 
-       snprintf(tempspool, sizeof tempspool, "./network/spoolin/ap.%d",
-               getpid());
+       unlink(tempspool);
 
-       tempfp = tmpfile();
+       tempfp = fopen(tempspool, "w+b");
+       unlink(tempspool);
        if (tempfp == NULL) {
                perror("cannot open temp file");
                exit(errno);
        }
 
        /* Generate a message from stdin */
-       make_message(tempfp, target_room, author);
+       ap_make_message(tempfp, target_room, author);
 
        /* Copy it to a new temp file in the spool directory */
        rewind(tempfp);
@@ -99,13 +121,12 @@ int main(int argc, char **argv)
                perror("cannot open spool file");
                exit(errno);
        }
-       while (ch = getc(tempfp), (ch >= 0))
+       while (ch = getc(tempfp), (ch >= 0)) {
                putc(ch, spoolfp);
+       }
 
        fclose(tempfp);
        fclose(spoolfp);
 
-       execlp("./netproc", "netproc", "-i", NULL);
-       perror("cannot run netproc");
-       exit(errno);
+       exit(0);
 }