[xiph-cvs] cvs commit: log log.c

Karl Heyes karl at xiph.org
Fri Jul 11 16:36:49 PDT 2003



karl        03/07/11 19:36:49

  Modified:    .        log.c
  Log:
  inverted logic used by some of the new functions fixed, locking updates
  and some code cleanups

Revision  Changes    Path
1.13      +19 -7     log/log.c

Index: log.c
===================================================================
RCS file: /usr/local/cvsroot/log/log.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- log.c	9 Jul 2003 02:45:22 -0000	1.12
+++ log.c	11 Jul 2003 23:36:49 -0000	1.13
@@ -179,14 +179,17 @@
 
 int log_set_filename(int id, const char *filename)
 {
-    if (id >= 0 && id < LOG_MAXLOGS)
+    if (id < 0 || id >= LOG_MAXLOGS)
         return LOG_EINSANE;
-    if (filename == NULL || !strcmp(filename, "") || loglist [id] . in_use == 0)
+    if (!strcmp(filename, "") || loglist [id] . in_use == 0)
         return LOG_EINSANE;
      _lock_logger();
     if (loglist [id] . filename)
         free (loglist [id] . filename);
-    loglist [id] . filename = strdup (filename);
+    if (filename)
+        loglist [id] . filename = strdup (filename);
+    else
+        loglist [id] . filename = NULL;
      _unlock_logger();
     return id;
 }
@@ -220,14 +223,15 @@
 
 void log_reopen(int log_id)
 {
-    if (log_id >= 0 && log_id < LOG_MAXLOGS)
+    if (log_id < 0 && log_id >= LOG_MAXLOGS)
         return;
-    if (loglist [log_id] . filename)
+    if (loglist [log_id] . filename && loglist [log_id] . logfile)
     {
         _lock_logger();
 
         fclose (loglist [log_id] . logfile);
         loglist [log_id] . logfile = NULL;
+
         _unlock_logger();
     }
 }
@@ -235,14 +239,22 @@
 void log_close(int log_id)
 {
     if (log_id < 0 || log_id >= LOG_MAXLOGS) return;
+
+    _lock_logger();
+
     if (loglist[log_id].in_use == 0) return;
 
     loglist[log_id].in_use = 0;
     loglist[log_id].level = 2;
     if (loglist[log_id].filename) free(loglist[log_id].filename);
     if (loglist[log_id].buffer) free(loglist[log_id].buffer);
-    fclose(loglist[log_id].logfile);
-    loglist[log_id].logfile = NULL;
+
+    if (loglist [log_id] . logfile)
+    {
+        fclose (loglist [log_id] . logfile);
+        loglist [log_id] . logfile = NULL;
+    }
+    _unlock_logger();
 }
 
 void log_shutdown()

<p><p>--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list