Commit 1a7e7bb0 authored by Conrad Parker's avatar Conrad Parker

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

svn path=/trunk/vorbis-tools/; revision=12222
parent d4a5d861
......@@ -252,7 +252,7 @@ dnl --------------------------------------------------
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 --------------------------------------------------
......
......@@ -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 @@ void close_files(param_t *p, int output_written)
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 @@ void close_files(param_t *p, int output_written)
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 {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment