[libdvdcss-devel] [PATCH] Check the return values of write() calls.

Diego Biurrun diego at biurrun.de
Wed Mar 13 11:53:01 CET 2013


Fixes the following two warnings:
src/libdvdcss.c:380:18: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Wunused-result]
src/css.c:275:18: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Wunused-result]
---

Now with static const len variable.

 src/css.c       |    9 +++++++--
 src/libdvdcss.c |    7 ++++++-
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/src/css.c b/src/css.c
index 935b7b2..839fa29 100644
--- a/src/css.c
+++ b/src/css.c
@@ -266,13 +266,18 @@ int _dvdcss_title ( dvdcss_t dvdcss, int i_block )
         i_fd = open( dvdcss->psz_cachefile, O_RDWR|O_CREAT, 0644 );
         if( i_fd >= 0 )
         {
-            char psz_key[KEY_SIZE * 3 + 2];
+            static const ssize_t len = KEY_SIZE * 3 + 1;
+            char psz_key[len + 1];
 
             sprintf( psz_key, "%02x:%02x:%02x:%02x:%02x\r\n",
                               p_title_key[0], p_title_key[1], p_title_key[2],
                               p_title_key[3], p_title_key[4] );
 
-            write( i_fd, psz_key, KEY_SIZE * 3 + 1 );
+            if( write( i_fd, psz_key, len ) < len )
+            {
+                print_error( dvdcss,
+                             "Error caching key on disk, continuing..\n" );
+            }
             close( i_fd );
         }
     }
diff --git a/src/libdvdcss.c b/src/libdvdcss.c
index 2a1a5bb..f1fbd9d 100644
--- a/src/libdvdcss.c
+++ b/src/libdvdcss.c
@@ -377,7 +377,12 @@ LIBDVDCSS_EXPORT dvdcss_t dvdcss_open ( char *psz_target )
         i_fd = open( psz_tagfile, O_RDWR|O_CREAT, 0644 );
         if( i_fd >= 0 )
         {
-            write( i_fd, psz_tag, strlen(psz_tag) );
+            ssize_t len = strlen(psz_tag);
+            if( write( i_fd, psz_tag, len ) < len )
+            {
+                print_error( dvdcss,
+                             "Error writing cache directory tag, continuing..\n" );
+            }
             close( i_fd );
         }
     }
-- 
1.7.9.5



More information about the libdvdcss-devel mailing list