diff --git a/ChangeLog b/ChangeLog index f88d2be3..44aa237b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -18639,3 +18639,5 @@ * Updated the package version to 3.0.0rc01. 2019-05-03 Fred Gleason * Fixed a regression that broke audio importation in rdimport(1). +2019-05-03 Fred Gleason + * Cleaned up a compiler warning for rdimport(1). diff --git a/lib/rdconf.cpp b/lib/rdconf.cpp index 9757df1f..c6f85fb9 100644 --- a/lib/rdconf.cpp +++ b/lib/rdconf.cpp @@ -740,7 +740,7 @@ int RDSetTimeLength(const QString &str) return res; } - +/* bool RDCopy(const QString &srcfile,const QString &destfile) { int src_fd; @@ -777,6 +777,81 @@ bool RDCopy(const QString &srcfile,const QString &destfile) close(dest_fd); return true; } +*/ + +bool RDCopy(const QString &srcfile,const QString &destfile) +{ + int src_fd; + int dest_fd; + + if((src_fd=open((const char *)srcfile,O_RDONLY))<0) { + return false; + } + if((dest_fd=open((const char *)destfile,O_WRONLY|O_CREAT,S_IWUSR))<0) { + close(src_fd); + return false; + } + bool ret=RDCopy(src_fd,dest_fd); + close(src_fd); + close(dest_fd); + + return ret; +} + + +bool RDCopy(const QString &srcfile,int dest_fd) +{ + int src_fd; + + if((src_fd=open((const char *)srcfile,O_RDONLY))<0) { + return false; + } + bool ret=RDCopy(src_fd,dest_fd); + close(src_fd); + + return ret; +} + + +bool RDCopy(int src_fd,const QString &destfile) +{ + int dest_fd; + + if((dest_fd=open((const char *)destfile,O_WRONLY|O_CREAT,S_IWUSR))<0) { + return false; + } + bool ret=RDCopy(src_fd,dest_fd); + close(dest_fd); + + return ret; +} + + +bool RDCopy(int src_fd,int dest_fd) +{ + struct stat src_stat; + struct stat dest_stat; + char *buf=NULL; + int n; + + if(fstat(src_fd,&src_stat)<0) { + return false; + } + if(fstat(dest_fd,&dest_stat)<0) { + return false; + } + if(fchmod(dest_fd,src_stat.st_mode)<0) { + return false; + } + buf=(char *)malloc(dest_stat.st_blksize); + while((n=read(src_fd,buf,dest_stat.st_blksize))==dest_stat.st_blksize) { + write(dest_fd,buf,dest_stat.st_blksize); + } + write(dest_fd,buf,n); + free(buf); + + return true; +} bool RDWritePid(const QString &dirname,const QString &filename,int owner, diff --git a/lib/rdconf.h b/lib/rdconf.h index b5e9b231..a84ce2c9 100644 --- a/lib/rdconf.h +++ b/lib/rdconf.h @@ -84,6 +84,9 @@ bool RDIsSqlNull(const QString &table,const QString &name,unsigned test, QString RDGetTimeLength(int mseconds,bool leadzero=false,bool tenths=true); int RDSetTimeLength(const QString &string); bool RDCopy(const QString &srcfile,const QString &destfile); +bool RDCopy(const QString &srcfile,int dest_fd); +bool RDCopy(int src_fd,const QString &destfile); +bool RDCopy(int src_fd,int dest_fd); bool RDWritePid(const QString &dirname,const QString &filename,int owner=-1, int group=-1); void RDDeletePid(const QString &dirname,const QString &filename); diff --git a/utils/rdimport/rdimport.cpp b/utils/rdimport/rdimport.cpp index be42b368..05c4da99 100644 --- a/utils/rdimport/rdimport.cpp +++ b/utils/rdimport/rdimport.cpp @@ -1480,14 +1480,18 @@ RDWaveFile *MainObject::FixFile(const QString &filename,RDWaveData *wavedata) // // Copy File // - import_temp_fix_filename= - QString(tempnam(RDTempDirectory::basePath(),"rdfix"))+QString(".wav"); - if(import_temp_fix_filename.isNull()) { + char tempfile[PATH_MAX]; + strncpy(tempfile,RDTempDirectory::basePath()+ + QString().sprintf("/rdimport%dXXXXXX",getpid()),PATH_MAX); + int dest_fd=mkstemp(tempfile); + if(dest_fd<0) { return NULL; } - if(!RDCopy(filename,import_temp_fix_filename)) { + import_temp_fix_filename=tempfile; + if(!RDCopy(filename,dest_fd)) { return NULL; } + close(dest_fd); // // Apply Fix