vdr-xine 0.7.6: kill a few compiler warnings

Message ID 4DE7CF521D%linux@youmustbejoking.demon.co.uk
State New
Headers

Commit Message

Darren Salt Jan. 12, 2006, 12:54 a.m. UTC
  This patch prevents some printf format string warnings when building vdr-xine
0.7.6 with these extra flags:
  -Wall -Wnonnull -Wformat=2 -Wextra

(There are potential problems if the fifo directory's name contains % and
mkdir or mknod fails. This patch eliminates them.)
  

Comments

Reinhard Nissl Jan. 14, 2006, 8:09 p.m. UTC | #1
Hi,

Darren Salt wrote:

> This patch prevents some printf format string warnings when building vdr-xine
> 0.7.6 with these extra flags:
>   -Wall -Wnonnull -Wformat=2 -Wextra
> 
> (There are potential problems if the fifo directory's name contains % and
> mkdir or mknod fails. This patch eliminates them.)

Thank you for this patch. I'll integrate it into release 0.7.7.

Bye.
  

Patch

diff -urNad vdr-plugin-xine-0.7.6~/xineLib.c vdr-plugin-xine-0.7.6/xineLib.c
--- vdr-plugin-xine-0.7.6~/xineLib.c	2006-01-12 01:21:23.599614013 +0000
+++ vdr-plugin-xine-0.7.6/xineLib.c	2006-01-12 01:21:47.774014821 +0000
@@ -1912,8 +1912,8 @@ 
     }
     else
     {
-      ::fprintf(stderr, ("vdr-xine: error: couldn't open '" + noSignalFileName + "'!\n").c_str());
-      esyslog(("vdr-xine: error: couldn't open '" + noSignalFileName + "'!\n").c_str());
+      ::fprintf(stderr, "vdr-xine: error: couldn't open '%s'!\n", noSignalFileName.c_str());
+      esyslog("vdr-xine: error: couldn't open '%s'!\n", noSignalFileName.c_str());
     }
 
     assert(remote);
@@ -1953,69 +1953,32 @@ 
 
     const mode_t origUmask = ::umask(0);
     
-    if (::mkdir(m_fifoDir.c_str(), 0755) < 0)
-    {
-      perror(("vdr-xine: error: couldn't create directory '" + m_fifoDir + "'").c_str());
-      esyslog(("vdr-xine: error: couldn't create directory '" + m_fifoDir + "'").c_str());
-
-      ::umask(origUmask);
-      return false;
-    }
-    
-    if (::mknod(m_fifoNameExtControl.c_str(), 0666 | S_IFIFO, 0) < 0)
-    {
-      perror(("vdr-xine: error: couldn't create fifo '" + m_fifoNameExtControl + "'").c_str());
-      esyslog(("vdr-xine: error: couldn't create fifo '" + m_fifoNameExtControl + "'").c_str());
-
-      ::umask(origUmask);
-      return false;
-    }
-
-    if (::mknod(m_fifoNameExtResult.c_str(), 0644 | S_IFIFO, 0) < 0)
-    {
-      perror(("vdr-xine: error: couldn't create fifo '" + m_fifoNameExtResult + "'").c_str());
-      esyslog(("vdr-xine: error: couldn't create fifo '" + m_fifoNameExtResult + "'").c_str());
-
-      ::umask(origUmask);
-      return false;
-    }
-
-    if (::mknod(m_fifoNameControl.c_str(), 0644 | S_IFIFO, 0) < 0)
-    {
-      perror(("vdr-xine: error: couldn't create fifo '" + m_fifoNameControl + "'").c_str());
-      esyslog(("vdr-xine: error: couldn't create fifo '" + m_fifoNameControl + "'").c_str());
-
-      ::umask(origUmask);
-      return false;
-    }
-
-    if (::mknod(m_fifoNameResult.c_str(), 0666 | S_IFIFO, 0) < 0)
-    {
-      perror(("vdr-xine: error: couldn't create fifo '" + m_fifoNameResult + "'").c_str());
-      esyslog(("vdr-xine: error: couldn't create fifo '" + m_fifoNameResult + "'").c_str());
-
-      ::umask(origUmask);
-      return false;
-    }
+#define MkFifo(String, Mask) \
+	do { if (::mknod((String).c_str(), (Mask) | S_IFIFO, 0) < 0) \
+	{ \
+	  string msg = "vdr-xine: error: couldn't create fifo '" + (String) + "'"; \
+	  perror(msg.c_str()); \
+	  esyslog("%s", msg.c_str()); \
+	  ::umask(origUmask); \
+	  return false; \
+	} } while (0)
 
-    if (::mknod(m_fifoNameRemote.c_str(), 0666 | S_IFIFO, 0) < 0)
+    if (::mkdir(m_fifoDir.c_str(), 0755) < 0)
     {
-      perror(("vdr-xine: error: couldn't create fifo '" + m_fifoNameRemote + "'").c_str());
-      esyslog(("vdr-xine: error: couldn't create fifo '" + m_fifoNameRemote + "'").c_str());
-
+      string msg = "vdr-xine: error: couldn't create directory '" + m_fifoDir + "'";
+      perror(msg.c_str());
+      esyslog("%s", msg.c_str());
       ::umask(origUmask);
       return false;
     }
 
-    if (::mknod(m_fifoNameStream.c_str(), 0644 | S_IFIFO, 0) < 0)
-    {
-      perror(("vdr-xine: error: couldn't create fifo '" + m_fifoNameStream + "'").c_str());
-      esyslog(("vdr-xine: error: couldn't create fifo '" + m_fifoNameStream + "'").c_str());
+    MkFifo(m_fifoNameExtControl, 0666);
+    MkFifo(m_fifoNameExtResult,  0644);
+    MkFifo(m_fifoNameControl,    0644);
+    MkFifo(m_fifoNameResult,     0666);
+    MkFifo(m_fifoNameRemote,     0666);
+    MkFifo(m_fifoNameStream,     0644);
 
-      ::umask(origUmask);
-      return false;
-    }
-    
     ::umask(origUmask);
     
     if (!Start())