* snprintf.c, snprintf.h: new files
authorNathan Bryant <loanshark@uncensored.citadel.org>
Wed, 7 Oct 1998 23:46:11 +0000 (23:46 +0000)
committerNathan Bryant <loanshark@uncensored.citadel.org>
Wed, 7 Oct 1998 23:46:11 +0000 (23:46 +0000)
        * Makefile.in, configure.in, dynloader.c, sysdep.c: support for the
          above; citserver now builds and runs on Digital Unix 4.0d with the
          GNU-style configure script. there is a bug with the hostname display
          in the wholist.
        * netproc.c: sillyness fix
        * room_ops.h: prototype delete_room()

citadel/ChangeLog
citadel/Makefile.in
citadel/configure.in
citadel/dynloader.c
citadel/netproc.c
citadel/room_ops.h
citadel/snprintf.c [new file with mode: 0644]
citadel/snprintf.h [new file with mode: 0644]
citadel/sysdep.c

index 63eb1f3e215386c3e2a24de15aab662de83315bf..36cde8e485603477ea9f7847b0b93cf46484f584 100644 (file)
@@ -1,3 +1,12 @@
+1998-10-07 Nathan Bryant <bryant@cs.usm.maine.edu>
+       * snprintf.c, snprintf.h: new files
+       * Makefile.in, configure.in, dynloader.c, sysdep.c: support for the
+         above; citserver now builds and runs on Digital Unix 4.0d with the
+         GNU-style configure script. there is a bug with the hostname display
+         in the wholist.
+       * netproc.c: sillyness fix
+       * room_ops.h: prototype delete_room()
+
 Mon Oct  5 17:01:32 EDT 1998 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
        * Began fixing the stuff I broke
 
index 0ffce1b9c3258cdfe8daeb96085a3a28266eb835..7a9b1545c57c8717988a2c0e021961b7052fab96 100644 (file)
@@ -28,6 +28,7 @@ LIBS=@LIBS@
 LDFLAGS=@LDFLAGS@
 SERVER_LDFLAGS=@SERVER_LDFLAGS@
 CURSES=@CURSES@
+SNPRINTF=@SNPRINTF@
 PTHREAD_DEFS=-D_REENTRANT
 
 client: $(CLIENT_TARGETS)
@@ -86,17 +87,20 @@ serv_info.o: serv_info.c
 citserver: citserver.o user_ops.o support.o room_ops.o file_ops.o \
        msgbase.o config.o sysdep.o locate_host.o \
        housekeeping.o database.o control.o logging.o \
-       dynloader.o
+       dynloader.o $(SNPRINTF)
        $(CC) \
                citserver.o user_ops.o room_ops.o file_ops.o support.o \
                msgbase.o config.o sysdep.o locate_host.o \
                housekeeping.o database.o control.o logging.o \
-               dynloader.o \
+               dynloader.o $(SNPRINTF)\
                $(LDFLAGS) $(SERVER_LDFLAGS) $(LIBS) -o citserver
 
 citserver.o: citserver.c
        $(CC) $(CFLAGS) $(CPPFLAGS) $(DEFS) $(PTHREAD_DEFS) -c citserver.c
 
+snprintf.o: snprintf.c
+       $(CC) $(CFLAGS) $(CPPFLAGS) $(DEFS) $(PTHREAD_DEFS) -c snprintf.c
+
 user_ops.o: user_ops.c
        $(CC) $(CFLAGS) $(CPPFLAGS) $(DEFS) $(PTHREAD_DEFS) -c user_ops.c
 
index 90613572f2b1215962d3fbe8df664d9f63810a6a..813325cd650296e48920e90a6e1cac516612abd7 100644 (file)
@@ -68,10 +68,15 @@ AC_FUNC_GETPGRP
 AC_PROG_GCC_TRADITIONAL
 AC_TYPE_SIGNAL
 AC_FUNC_VPRINTF
-AC_CHECK_FUNCS(mkdir mktime rmdir select socket strerror)
+AC_CHECK_FUNCS(snprintf mkdir mktime rmdir select socket strerror)
+
+if test "$ac_cv_func_snprintf" = no; then
+       SNPRINTF=snprintf.o
+fi
 
 AC_SUBST(CURSES)
 AC_SUBST(TARGETS)
 AC_SUBST(SERVER_LDFLAGS)
+AC_SUBST(SNPRINTF)
 AC_CONFIG_HEADER(sysdep.h)
 AC_OUTPUT(Makefile)
index c8ed926d40d8b46df1f94dd28b80d7f86e6ccac6..0f492be0bd71985ccb85edfa8f79a797dccb038e 100644 (file)
 #include "server.h"
 #include "sysdep_decls.h"
 
+#ifndef HAVE_SNPRINTF
+#include <stdarg.h>
+#include "snprintf.h"
+#endif
+
 struct CleanupFunctionHook *CleanupHookTable = NULL;
 struct SessionFunctionHook *SessionHookTable = NULL;
 struct UserFunctionHook *UserHookTable = NULL;
index a665961e5ab32818758b3e2ea4fbd0bd49961e5b..83dd9c72c5c5895c850c636d536916d1687b3c43 100644 (file)
@@ -1217,7 +1217,7 @@ int main(int argc, char **argv)
        /*
         * Change directories if specified
         */
-       if (argv > 0) for (a=1; a<argc; ++a) {
+       for (a=1; a<argc; ++a) {
                if (!strncmp(argv[a], "-h", 2)) {
                        strcpy(bbs_home_directory, argv[a]);
                        strcpy(bbs_home_directory, &bbs_home_directory[2]);
index 1b3ea9536f8ec573975f6c425c3238e7752e757f..76514af017b2c739933750ec26eea4002be06d43 100644 (file)
@@ -44,3 +44,4 @@ void cmd_kflr (char *argbuf);
 void cmd_eflr (char *argbuf);
 void ForEachRoom(void (*CallBack)(struct quickroom *EachRoom));
 void assoc_file_name(char *buf, struct quickroom *qrbuf, char *prefix);
+void delete_room(struct quickroom *qrbuf);
diff --git a/citadel/snprintf.c b/citadel/snprintf.c
new file mode 100644 (file)
index 0000000..693a259
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ * modified from Sten Gunterberg's BUGTRAQ post of 22 Jul 1997
+ * --nathan bryant <bryant@cs.usm.maine.edu>
+ */
+
+/*
+ * Replacements for snprintf() and vsnprintf()
+ *
+ * Use it only if you have the "spare" cycles needed to effectively
+ * do every snprintf operation twice! Why is that? Because everything
+ * is first vfprintf()'d to /dev/null to determine the number of bytes.
+ * Perhaps a bit slow for demanding applications on slow machines,
+ * no problem for a fast machine with some spare cycles.
+ *
+ * You don't have a /dev/null? Every Linux contains one for free!
+ *
+ * Because the format string is never even looked at, all current and
+ * possible future printf-conversions should be handled just fine.
+ *
+ * Written July 1997 by Sten Gunterberg (gunterberg@ergon.ch)
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+
+static int
+needed (const char *fmt, va_list argp)
+{
+  static FILE *sink = NULL;
+
+  /* ok, there's a small race here that could result in the sink being
+   * opened more than once if we're threaded, but I'd rather ignore it than
+   * spend cycles synchronizing :-) */
+
+  if (sink == NULL)
+    {
+      if ((sink = fopen("/dev/null", "w")) == NULL)
+       {
+         perror("/dev/null");
+         exit(1);
+       }
+    }
+
+  return vfprintf(sink, fmt, argp);
+}
+
+int
+snprintf (char *buf, size_t max, const char *fmt, ...)
+{
+  va_list argp;
+  int bytes;
+
+  va_start(argp, fmt);
+  bytes = vsnprintf(buf, max, fmt, argp);
+  va_end(argp);
+
+  return bytes;
+}
+
+int
+vsnprintf (char *buf, size_t max, const char *fmt, va_list argp)
+{
+  char *p;
+  int size;
+
+  if ((p = malloc(needed(fmt, argp) + 1)) == NULL)
+    {
+      fprintf(stderr, "vsnprintf: malloc failed, aborting\n");
+      abort();
+    }
+
+  if ((size = vsprintf(p, fmt, argp)) >= max)
+    size = -1;
+
+  strncpy(buf, p, max);
+  buf[max - 1] = 0;
+  free(p);
+  return size;
+}
diff --git a/citadel/snprintf.h b/citadel/snprintf.h
new file mode 100644 (file)
index 0000000..29fee85
--- /dev/null
@@ -0,0 +1,2 @@
+int snprintf (char *buf, size_t max, const char *fmt, ...);
+int vsnprintf (char *buf, size_t max, const char *fmt, va_list argp);
index 9f5adf9bf1e80cfb1232d8b92f0a7f5032630f82..8b8ad314bb09a8fdd7dcc36045663778c5c0ce21 100644 (file)
 #include <sys/select.h>
 #endif
 
+#ifndef HAVE_SNPRINTF
+#include "snprintf.h"
+#endif
+
 pthread_mutex_t Critters[MAX_SEMAPHORES];      /* Things needing locking */
 pthread_key_t MyConKey;                                /* TSD key for MyContext() */