]> git.pond.sub.org Git - empserver/blobdiff - src/lib/common/log.c
Update copyright notice.
[empserver] / src / lib / common / log.c
index e0d5e88e0cba560219337e25b857175bdb0da5bc..de7f8cd38f20a6b905d67264107a20a2d74b5d13 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2004, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
 #include <fcntl.h>
 #include <stdarg.h>
 #include <stdio.h>
-#ifdef Rel4
 #include <string.h>
-#endif /* Rel4 */
 #include <time.h>
-#include "deity.h"
 #include "player.h"
 #include "common.h"
+#include "optlist.h"
 
 static s_char *logfile = 0;
 
-s_char *
-getlogfile()
-{
-    return (s_char *)logfile;
-}
-
 /*
  * Points logfile at datadir/"program".log
  */
 void
-loginit(void)
+loginit(s_char *program)
 {
-    extern s_char program[];
-    extern s_char *datadir;
     s_char buf[1024];
 
 #if !defined(_WIN32)
@@ -87,15 +77,13 @@ logerror(s_char *format, ...)
     int logf;
     s_char *p;
 
-    if (logfile == 0)
-       loginit();
     va_start(list, format);
     vsprintf(buf, format, list);
-    if ((p = index(buf, '\n')) != 0)
+    if ((p = strchr(buf, '\n')) != 0)
        *p = 0;
     (void)time(&now);
     strcpy(cbuf, ctime(&now));
-    if ((p = index(cbuf, '\n')) != 0)
+    if ((p = strchr(cbuf, '\n')) != 0)
        *p = 0;
     (void)sprintf(buf1, "%s %s\n", cbuf, buf);
     if ((logf = open(logfile, O_WRONLY | O_CREAT | O_APPEND, 0666)) < 0)
@@ -111,3 +99,15 @@ logerror(s_char *format, ...)
 #endif
     va_end(list);
 }
+
+/*
+ * Log internal error MSG occured in FILE:LINE.
+ * If debugging, call abort(), else return 1.
+ */
+int
+oops(char *msg, char *file, int line)
+{
+  logerror("Oops: %s in %s:%d\n", msg, file, line);
+  if (debug) abort();
+  return 1;
+}