]> git.sesse.net Git - vlc/blobdiff - src/interface/intf_msg.c
. r�paration d'un oubli
[vlc] / src / interface / intf_msg.c
index da593aab9733c9031a2b5642e147a869e010ef7b..946d2f3ce463bf0c97d94675c0c7f6b855a0d242 100644 (file)
@@ -1,29 +1,49 @@
 /*****************************************************************************
  * intf_msg.c: messages interface
- * (c)1998 VideoLAN
- *****************************************************************************
  * This library provides basic functions for threads to interact with user
  * interface, such as message output. See config.h for output configuration.
+ *****************************************************************************
+ * Copyright (C) 1998, 1999, 2000 VideoLAN
+ *
+ * Authors:
+ *
+ * This program 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.
+ * 
+ * This program 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
  *****************************************************************************/
 
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <errno.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdarg.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
+#include "defs.h"
+
+#include <errno.h>                                                  /* errno */
+#include <fcntl.h>                     /* O_CREAT, O_TRUNC, O_WRONLY, O_SYNC */
+#include <stdio.h>                                               /* required */
+#include <stdarg.h>                                       /* va_list for BSD */
+#include <stdlib.h>                                              /* malloc() */
+#include <string.h>                                            /* strerror() */
+#include <unistd.h>                                      /* close(), write() */
 
 #include "config.h"
 #include "common.h"
+#include "threads.h"
 #include "mtime.h"
-#include "vlc_thread.h"
+#include "plugins.h"
 #include "intf_msg.h"
 #include "interface.h"
 #include "intf_console.h"
+
 #include "main.h"
 
 /*****************************************************************************
@@ -87,7 +107,7 @@ typedef struct intf_msg_s
  *****************************************************************************/
 
 static void QueueMsg        ( intf_msg_t *p_msg, int i_type,
-                             char *psz_format, va_list ap );
+                              char *psz_format, va_list ap );
 static void PrintMsg        ( intf_msg_item_t *p_msg );
 #ifdef DEBUG
 static void QueueDbgMsg     ( intf_msg_t *p_msg, char *psz_file,
@@ -100,7 +120,7 @@ static void FlushLockedMsg  ( intf_msg_t *p_msg );
 
 
 /*****************************************************************************
- * intf_MsgCreate: initialize messages interface                            (ok ?)
+ * intf_MsgCreate: initialize messages interface                         (ok ?)
  *****************************************************************************
  * This functions has to be called before any call to other intf_*Msg functions.
  * It set up the locks and the message queue if it is used.
@@ -113,7 +133,7 @@ p_intf_msg_t intf_MsgCreate( void )
     p_msg = malloc( sizeof( intf_msg_t ) );
     if( p_msg == NULL )
     {
-       errno = ENOMEM;
+        errno = ENOMEM;
     }
     else
     {
@@ -124,12 +144,17 @@ p_intf_msg_t intf_MsgCreate( void )
 #endif
 
 #ifdef DEBUG_LOG
-       /* Log file initialization - on failure, file pointer will be null,
-        * and no log will be issued, but this is not considered as an
-        * error */
-       p_msg->i_log_file = open( DEBUG_LOG,
-                                  O_CREAT | O_TRUNC | O_SYNC | O_WRONLY,
-                                  0666 );
+        /* Log file initialization - on failure, file pointer will be null,
+         * and no log will be issued, but this is not considered as an
+         * error */
+        p_msg->i_log_file = open( DEBUG_LOG, O_CREAT | O_TRUNC |
+#ifndef SYS_BSD
+                                  O_SYNC |
+#else
+                                  O_ASYNC |
+#endif /* SYS_BSD */
+                                  O_WRONLY, 0666 );
+
 #endif
     }
     return( p_msg );
@@ -150,7 +175,7 @@ void intf_MsgDestroy( void )
     /* Close log file if any */
     if( p_main->p_msg->i_log_file >= 0 )
     {
-       close( p_main->p_msg->i_log_file );
+        close( p_main->p_msg->i_log_file );
     }
 #endif
 
@@ -322,7 +347,12 @@ static void QueueMsg( intf_msg_t *p_msg, int i_type, char *psz_format, va_list a
     /*
      * Convert message to string
      */
+#ifdef SYS_BEOS
+    psz_str = (char*) malloc( strlen(psz_format) + INTF_MAX_MSG_SIZE );
+    vsprintf( psz_str, psz_format, ap );
+#else
     vasprintf( &psz_str, psz_format, ap );
+#endif
     if( psz_str == NULL )
     {
         fprintf(stderr, "warning: can't store following message (%s): ",
@@ -365,7 +395,7 @@ static void QueueMsg( intf_msg_t *p_msg, int i_type, char *psz_format, va_list a
  *****************************************************************************/
 #ifdef DEBUG
 static void QueueDbgMsg(intf_msg_t *p_msg, char *psz_file, char *psz_function,
-                       int i_line, char *psz_format, va_list ap)
+                        int i_line, char *psz_format, va_list ap)
 {
     char *                  psz_str;             /* formatted message string */
     intf_msg_item_t *       p_msg_item;                /* pointer to message */
@@ -378,13 +408,18 @@ static void QueueDbgMsg(intf_msg_t *p_msg, char *psz_file, char *psz_function,
     /*
      * Convert message to string
      */
+#ifdef SYS_BEOS
+    psz_str = (char*) malloc( INTF_MAX_MSG_SIZE );
+    vsprintf( psz_str, psz_format, ap );
+#else
     vasprintf( &psz_str, psz_format, ap );
+#endif
     if( psz_str == NULL )
     {
         fprintf(stderr, "warning: can't store following message (%s): ",
                 strerror(errno) );
         fprintf(stderr, INTF_MSG_DBG_FORMAT, psz_file, psz_function, i_line );
-       vfprintf(stderr, psz_format, ap );
+        vfprintf(stderr, psz_format, ap );
         exit( errno );
     }
 
@@ -509,7 +544,7 @@ static void PrintMsg( intf_msg_item_t *p_msg )
     /* Append all messages to log file */
     if( p_main->p_msg->i_log_file >= 0 )
     {
-       write( p_main->p_msg->i_log_file, psz_msg, strlen( psz_msg ) );
+        write( p_main->p_msg->i_log_file, psz_msg, strlen( psz_msg ) );
     }
 #endif