mirror of
https://github.com/upx/upx
synced 2025-09-28 19:06:07 +08:00
Cleanups.
committer: mfx <mfx> 1034748563 +0000
This commit is contained in:
parent
81efdd41f4
commit
1e1e333d61
14
src/file.cpp
14
src/file.cpp
|
@ -88,7 +88,7 @@ FileBase::~FileBase()
|
||||||
void FileBase::sopen()
|
void FileBase::sopen()
|
||||||
{
|
{
|
||||||
if (_shflags < 0)
|
if (_shflags < 0)
|
||||||
_fd = ::open(_name,_flags,_mode);
|
_fd = ::open(_name, _flags, _mode);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#if defined(__DJGPP__)
|
#if defined(__DJGPP__)
|
||||||
|
@ -96,7 +96,7 @@ void FileBase::sopen()
|
||||||
#elif defined(__MINT__)
|
#elif defined(__MINT__)
|
||||||
_fd = ::open(_name,_flags | (_shflags & O_SHMODE), _mode);
|
_fd = ::open(_name,_flags | (_shflags & O_SHMODE), _mode);
|
||||||
#elif defined(SH_DENYRW)
|
#elif defined(SH_DENYRW)
|
||||||
_fd = ::sopen(_name,_flags,_shflags,_mode);
|
_fd = ::sopen(_name, _flags, _shflags, _mode);
|
||||||
#else
|
#else
|
||||||
assert(0);
|
assert(0);
|
||||||
#endif
|
#endif
|
||||||
|
@ -135,9 +135,9 @@ int FileBase::read(void *buf, int len)
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
#if 1 && defined(__DJGPP__)
|
#if 1 && defined(__DJGPP__)
|
||||||
l = ::_read(_fd,buf,len);
|
l = ::_read(_fd, buf, len);
|
||||||
#else
|
#else
|
||||||
l = ::read(_fd,buf,len);
|
l = ::read(_fd, buf, len);
|
||||||
#endif
|
#endif
|
||||||
if (l < 0)
|
if (l < 0)
|
||||||
{
|
{
|
||||||
|
@ -155,7 +155,7 @@ int FileBase::read(void *buf, int len)
|
||||||
|
|
||||||
int FileBase::readx(void *buf, int len)
|
int FileBase::readx(void *buf, int len)
|
||||||
{
|
{
|
||||||
int l = this->read(buf,len);
|
int l = this->read(buf, len);
|
||||||
if (l != len)
|
if (l != len)
|
||||||
throwEOFException();
|
throwEOFException();
|
||||||
return l;
|
return l;
|
||||||
|
@ -204,7 +204,7 @@ off_t FileBase::tell() const
|
||||||
{
|
{
|
||||||
if (!isOpen())
|
if (!isOpen())
|
||||||
throwIOException("bad tell");
|
throwIOException("bad tell");
|
||||||
off_t l = ::lseek(_fd,0,SEEK_CUR);
|
off_t l = ::lseek(_fd, 0, SEEK_CUR);
|
||||||
if (l < 0)
|
if (l < 0)
|
||||||
throwIOException("tell error",errno);
|
throwIOException("tell error",errno);
|
||||||
return l;
|
return l;
|
||||||
|
@ -340,7 +340,7 @@ bool OutputFile::openStdout(int flags, bool force)
|
||||||
|
|
||||||
void OutputFile::write(const void *buf, int len)
|
void OutputFile::write(const void *buf, int len)
|
||||||
{
|
{
|
||||||
super::write(buf,len);
|
super::write(buf, len);
|
||||||
bytes_written += len;
|
bytes_written += len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
14
src/util.cpp
14
src/util.cpp
|
@ -411,7 +411,7 @@ bool file_exists(const char *name)
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
|
||||||
/* return true if we can open it */
|
/* return true if we can open it */
|
||||||
fd = open(name, O_RDONLY);
|
fd = open(name, O_RDONLY, 0);
|
||||||
if (fd >= 0)
|
if (fd >= 0)
|
||||||
{
|
{
|
||||||
(void) close(fd);
|
(void) close(fd);
|
||||||
|
@ -440,7 +440,7 @@ bool maketempname(char *ofilename, size_t size,
|
||||||
const char *ifilename, const char *ext, bool force)
|
const char *ifilename, const char *ext, bool force)
|
||||||
{
|
{
|
||||||
char *ofext = NULL, *ofname;
|
char *ofext = NULL, *ofname;
|
||||||
int ofile = -1;
|
int ofile;
|
||||||
|
|
||||||
if (size <= 0)
|
if (size <= 0)
|
||||||
return false;
|
return false;
|
||||||
|
@ -455,14 +455,14 @@ bool maketempname(char *ofilename, size_t size,
|
||||||
ofext = ofilename + strlen(ofilename);
|
ofext = ofilename + strlen(ofilename);
|
||||||
strcpy(ofext, ext);
|
strcpy(ofext, ext);
|
||||||
|
|
||||||
while (ofile < 1000)
|
for (ofile = 0; ofile < 1000; ofile++)
|
||||||
{
|
{
|
||||||
assert(strlen(ofilename) < size);
|
assert(strlen(ofilename) < size);
|
||||||
if (!file_exists(ofilename))
|
if (!file_exists(ofilename))
|
||||||
return true;
|
return true;
|
||||||
if (!force)
|
if (!force)
|
||||||
break;
|
break;
|
||||||
upx_snprintf(ofext, 5, ".%03d", ++ofile);
|
upx_snprintf(ofext, 5, ".%03d", ofile);
|
||||||
}
|
}
|
||||||
|
|
||||||
ofilename[0] = 0;
|
ofilename[0] = 0;
|
||||||
|
@ -474,7 +474,7 @@ bool makebakname(char *ofilename, size_t size,
|
||||||
const char *ifilename, bool force)
|
const char *ifilename, bool force)
|
||||||
{
|
{
|
||||||
char *ofext = NULL, *ofname;
|
char *ofext = NULL, *ofname;
|
||||||
int ofile = -1;
|
int ofile;
|
||||||
|
|
||||||
if (size <= 0)
|
if (size <= 0)
|
||||||
return false;
|
return false;
|
||||||
|
@ -495,14 +495,14 @@ bool makebakname(char *ofilename, size_t size,
|
||||||
else
|
else
|
||||||
ofext[strlen(ofext)-1] = '~';
|
ofext[strlen(ofext)-1] = '~';
|
||||||
|
|
||||||
while (ofile < 1000)
|
for (ofile = 0; ofile < 1000; ofile++)
|
||||||
{
|
{
|
||||||
assert(strlen(ofilename) < size);
|
assert(strlen(ofilename) < size);
|
||||||
if (!file_exists(ofilename))
|
if (!file_exists(ofilename))
|
||||||
return true;
|
return true;
|
||||||
if (!force)
|
if (!force)
|
||||||
break;
|
break;
|
||||||
upx_snprintf(ofext, 5, ".%03d", ++ofile);
|
upx_snprintf(ofext, 5, ".%03d", ofile);
|
||||||
}
|
}
|
||||||
|
|
||||||
ofilename[0] = 0;
|
ofilename[0] = 0;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user