diff options
author | XhmikosR <xhmikosr@users.sourceforge.net> | 2014-03-18 18:04:42 +0400 |
---|---|---|
committer | XhmikosR <xhmikosr@users.sourceforge.net> | 2014-03-19 13:00:00 +0400 |
commit | 7d361f58b65264857e2244964914640efb7cfaa4 (patch) | |
tree | 40b64163d0b6d92d623df37416dae046ea73d9f6 /src/thirdparty/unrar/file.cpp | |
parent | 44c3827e1f29793f00fda52407066ecfa79e5f0c (diff) |
Update unrar to v5.1.1.
Diffstat (limited to 'src/thirdparty/unrar/file.cpp')
-rw-r--r-- | src/thirdparty/unrar/file.cpp | 75 |
1 files changed, 55 insertions, 20 deletions
diff --git a/src/thirdparty/unrar/file.cpp b/src/thirdparty/unrar/file.cpp index 0da3f3d4a..4524fbeed 100644 --- a/src/thirdparty/unrar/file.cpp +++ b/src/thirdparty/unrar/file.cpp @@ -36,6 +36,7 @@ void File::operator = (File &SrcFile) NewFile=SrcFile.NewFile; LastWrite=SrcFile.LastWrite; HandleType=SrcFile.HandleType; + wcsncpyz(FileName,SrcFile.FileName,ASIZE(FileName)); SrcFile.SkipClose=true; } @@ -110,7 +111,16 @@ bool File::Open(const wchar *Name,uint Mode) return false; } #endif - hNewFile=handle==-1 ? BAD_HANDLE:fdopen(handle,UpdateMode ? UPDATEBINARY:READBINARY); + if (handle==-1) + hNewFile=BAD_HANDLE; + else + { +#ifdef FILE_USE_OPEN + hNewFile=handle; +#else + hNewFile=fdopen(handle,UpdateMode ? UPDATEBINARY:READBINARY); +#endif + } if (hNewFile==BAD_HANDLE && errno==ENOENT) ErrorType=FILE_NOTFOUND; #endif @@ -169,8 +179,12 @@ bool File::Create(const wchar *Name,uint Mode) #else char NameA[NM]; WideToChar(Name,NameA,ASIZE(NameA)); +#ifdef FILE_USE_OPEN + hFile=open(NameA,(O_CREAT|O_TRUNC) | (WriteMode ? O_WRONLY : O_RDWR)); +#else hFile=fopen(NameA,WriteMode ? WRITEBINARY:CREATEBINARY); #endif +#endif NewFile=true; HandleType=FILE_HANDLENORMAL; SkipClose=false; @@ -192,7 +206,6 @@ bool File::WCreate(const wchar *Name,uint Mode) { if (Create(Name,Mode)) return true; - ErrHandler.SetErrorCode(RARX_CREATE); ErrHandler.CreateErrorMsg(Name); return false; } @@ -212,8 +225,12 @@ bool File::Close() if (HandleType==FILE_HANDLENORMAL) Success=CloseHandle(hFile)==TRUE; #else +#ifdef FILE_USE_OPEN + Success=close(hFile)!=-1; +#else Success=fclose(hFile)!=EOF; #endif +#endif } hFile=BAD_HANDLE; } @@ -224,16 +241,6 @@ bool File::Close() } -void File::Flush() -{ -#ifdef _WIN_ALL - FlushFileBuffers(hFile); -#else - fflush(hFile); -#endif -} - - bool File::Delete() { if (HandleType!=FILE_HANDLENORMAL) @@ -272,7 +279,13 @@ void File::Write(const void *Data,size_t Size) #else // Cannot use the standard stdout here, because it already has wide orientation. if (hFile==BAD_HANDLE) - hFile=fdopen(dup(1),"w"); // Open new stdout stream. + { +#ifdef FILE_USE_OPEN + hFile=dup(STDOUT_FILENO); // Open new stdout stream. +#else + hFile=fdopen(dup(STDOUT_FILENO),"w"); // Open new stdout stream. +#endif + } #endif } while (1) @@ -294,9 +307,14 @@ void File::Write(const void *Data,size_t Size) else Success=WriteFile(hFile,Data,(DWORD)Size,&Written,NULL)==TRUE; #else +#ifdef FILE_USE_OPEN + ssize_t Written=write(hFile,Data,Size); + Success=Written==Size; +#else int Written=fwrite(Data,1,Size,hFile); Success=Written==Size && !ferror(hFile); #endif +#endif if (!Success && AllowExceptions && HandleType==FILE_HANDLENORMAL) { #if defined(_WIN_ALL) && !defined(SFX_MODULE) && !defined(RARDLL) @@ -309,7 +327,7 @@ void File::Write(const void *Data,size_t Size) #endif if (ErrHandler.AskRepeatWrite(FileName,false)) { -#ifndef _WIN_ALL +#if !defined(_WIN_ALL) && !defined(FILE_USE_OPEN) clearerr(hFile); #endif if (Written<Size && Written>0) @@ -376,8 +394,12 @@ int File::DirectRead(void *Data,size_t Size) Size=MaxDeviceRead; hFile=GetStdHandle(STD_INPUT_HANDLE); #else +#ifdef FILE_USE_OPEN + hFile=STDIN_FILENO; +#else hFile=stdin; #endif +#endif } #ifdef _WIN_ALL DWORD Read; @@ -402,6 +424,12 @@ int File::DirectRead(void *Data,size_t Size) } return Read; #else +#ifdef FILE_USE_OPEN + ssize_t ReadSize=read(hFile,Data,Size); + if (ReadSize==-1) + return -1; + return (int)ReadSize; +#else if (LastWrite) { fflush(hFile); @@ -413,6 +441,7 @@ int File::DirectRead(void *Data,size_t Size) return -1; return (int)ReadSize; #endif +#endif } @@ -439,13 +468,17 @@ bool File::RawSeek(int64 Offset,int Method) return false; #else LastWrite=false; -#if defined(_LARGEFILE_SOURCE) && !defined(_OSF_SOURCE) && !defined(__VMS) +#ifdef FILE_USE_OPEN + if (lseek64(hFile,Offset,Method)==-1) + return false; +#elif defined(_LARGEFILE_SOURCE) && !defined(_OSF_SOURCE) && !defined(__VMS) if (fseeko(hFile,Offset,Method)!=0) + return false; #else if (fseek(hFile,(long)Offset,Method)!=0) -#endif return false; #endif +#endif return true; } @@ -467,7 +500,9 @@ int64 File::Tell() return -1; return INT32TO64(HighDist,LowDist); #else -#if defined(_LARGEFILE_SOURCE) && !defined(_OSF_SOURCE) +#ifdef FILE_USE_OPEN + return lseek64(hFile,0,SEEK_CUR); +#elif defined(_LARGEFILE_SOURCE) && !defined(_OSF_SOURCE) return ftello(hFile); #else return ftell(hFile); @@ -489,7 +524,7 @@ void File::Prealloc(int64 Size) #if defined(_UNIX) && defined(USE_FALLOCATE) // fallocate is rather new call. Only latest kernels support it. // So we are not using it by default yet. - int fd = fileno(hFile); + int fd = GetFD(hFile); if (fd >= 0) fallocate(fd, 0, 0, Size); #endif @@ -585,7 +620,7 @@ void File::GetOpenFileTime(RarTime *ft) #endif #if defined(_UNIX) || defined(_EMX) struct stat st; - fstat(fileno(hFile),&st); + fstat(GetFD(),&st); *ft=st.st_mtime; #endif } @@ -607,7 +642,7 @@ bool File::IsDevice() uint Type=GetFileType(hFile); return Type==FILE_TYPE_CHAR || Type==FILE_TYPE_PIPE; #else - return isatty(fileno(hFile)); + return isatty(GetFD()); #endif } |