[xiph-commits] r12222 - in trunk/vorbis-tools: . vorbiscomment

conrad at svn.xiph.org conrad at svn.xiph.org
Sat Dec 16 23:46:50 PST 2006


Author: conrad
Date: 2006-12-16 23:46:48 -0800 (Sat, 16 Dec 2006)
New Revision: 12222

Modified:
   trunk/vorbis-tools/configure.ac
   trunk/vorbis-tools/vorbiscomment/vcomment.c
Log:
Added portability checks for stat, chmod in order to allow vorbiscomment to
preserve permission bits on platforms which support those calls. Code is
unchanged for platforms which don't have those calls and don't define the
macros to enable this. Closes ticket:1085


Modified: trunk/vorbis-tools/configure.ac
===================================================================
--- trunk/vorbis-tools/configure.ac	2006-12-17 07:32:45 UTC (rev 12221)
+++ trunk/vorbis-tools/configure.ac	2006-12-17 07:46:48 UTC (rev 12222)
@@ -252,7 +252,7 @@
 
 AC_FUNC_ALLOCA
 AM_ICONV
-AC_CHECK_FUNCS(atexit on_exit fcntl select)
+AC_CHECK_FUNCS(atexit on_exit fcntl select stat chmod)
 AM_LANGINFO_CODESET
 
 dnl --------------------------------------------------

Modified: trunk/vorbis-tools/vorbiscomment/vcomment.c
===================================================================
--- trunk/vorbis-tools/vorbiscomment/vcomment.c	2006-12-17 07:32:45 UTC (rev 12221)
+++ trunk/vorbis-tools/vorbiscomment/vcomment.c	2006-12-17 07:46:48 UTC (rev 12222)
@@ -17,6 +17,12 @@
 #include <stdlib.h>
 #include <locale.h>
 
+#if HAVE_STAT && HAVE_CHMOD
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#endif
+
 #include "getopt.h"
 #include "utf8.h"
 #include "i18n.h"
@@ -571,6 +577,11 @@
   if (p->com != NULL && p->com != stdout && p->com != stdin) fclose(p->com);
 
   if(p->tempoutfile) {
+#if HAVE_STAT && HAVE_CHMOD
+    struct stat st;
+    stat (p->infilename, &st);
+#endif
+    
     if(output_written) {
       /* Some platforms fail to rename a file if the new name already 
        * exists, so we need to remove, then rename. How stupid.
@@ -581,6 +592,10 @@
         else if(rename(p->outfilename, p->infilename)) 
           fprintf(stderr, _("Error renaming %s to %s\n"), p->outfilename, 
                   p->infilename);
+      } else {
+#if HAVE_STAT && HAVE_CHMOD
+        chmod (p->infilename, st.st_mode);
+#endif
       }
     }
     else {



More information about the commits mailing list