Use casts that are more portable.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42177 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold
2011-06-14 11:27:24 +00:00
parent 32a44923a6
commit e76046d3f9
+15 -15
View File
@@ -174,8 +174,8 @@ BMemoryIO::ReadAt(off_t pos, void *buffer, size_t size)
return B_BAD_VALUE; return B_BAD_VALUE;
ssize_t sizeRead = 0; ssize_t sizeRead = 0;
if (pos < fLength) { if (pos < (off_t)fLength) {
sizeRead = min_c(static_cast<off_t>(size), fLength - pos); sizeRead = min_c((off_t)size, (off_t)fLength - pos);
memcpy(buffer, fBuffer + pos, sizeRead); memcpy(buffer, fBuffer + pos, sizeRead);
} }
return sizeRead; return sizeRead;
@@ -184,20 +184,20 @@ BMemoryIO::ReadAt(off_t pos, void *buffer, size_t size)
ssize_t ssize_t
BMemoryIO::WriteAt(off_t pos, const void *buffer, size_t size) BMemoryIO::WriteAt(off_t pos, const void *buffer, size_t size)
{ {
if (fReadOnly) if (fReadOnly)
return B_NOT_ALLOWED; return B_NOT_ALLOWED;
if (buffer == NULL || pos < 0) if (buffer == NULL || pos < 0)
return B_BAD_VALUE; return B_BAD_VALUE;
ssize_t sizeWritten = 0; ssize_t sizeWritten = 0;
if (pos < fBufferSize) { if (pos < (off_t)fBufferSize) {
sizeWritten = min_c(static_cast<off_t>(size), fBufferSize - pos); sizeWritten = min_c((off_t)size, (off_t)fBufferSize - pos);
memcpy(fBuffer + pos, buffer, sizeWritten); memcpy(fBuffer + pos, buffer, sizeWritten);
} }
if (pos + sizeWritten > fLength) if (pos + sizeWritten > (off_t)fLength)
fLength = pos + sizeWritten; fLength = pos + sizeWritten;
return sizeWritten; return sizeWritten;
@@ -213,13 +213,13 @@ BMemoryIO::Seek(off_t position, uint32 seek_mode)
break; break;
case SEEK_CUR: case SEEK_CUR:
fPosition += position; fPosition += position;
break; break;
case SEEK_END: case SEEK_END:
fPosition = fLength + position; fPosition = fLength + position;
break; break;
default: default:
break; break;
} }
return fPosition; return fPosition;
} }
@@ -237,7 +237,7 @@ BMemoryIO::SetSize(off_t size)
if (fReadOnly) if (fReadOnly)
return B_NOT_ALLOWED; return B_NOT_ALLOWED;
if (size > fBufferSize) if (size > (off_t)fBufferSize)
return B_ERROR; return B_ERROR;
fLength = size; fLength = size;
@@ -293,8 +293,8 @@ BMallocIO::ReadAt(off_t pos, void *buffer, size_t size)
return B_BAD_VALUE; return B_BAD_VALUE;
ssize_t sizeRead = 0; ssize_t sizeRead = 0;
if (pos < fLength) { if (pos < (off_t)fLength) {
sizeRead = min_c(static_cast<off_t>(size), fLength - pos); sizeRead = min_c((off_t)size, (off_t)fLength - pos);
memcpy(buffer, fData + pos, sizeRead); memcpy(buffer, fData + pos, sizeRead);
} }
return sizeRead; return sizeRead;
@@ -307,7 +307,7 @@ BMallocIO::WriteAt(off_t pos, const void *buffer, size_t size)
if (buffer == NULL) if (buffer == NULL)
return B_BAD_VALUE; return B_BAD_VALUE;
size_t newSize = max_c(pos + size, static_cast<off_t>(fLength)); size_t newSize = max_c(pos + (off_t)size, (off_t)fLength);
status_t error = B_OK; status_t error = B_OK;
if (newSize > fMallocSize) if (newSize > fMallocSize)
@@ -361,12 +361,12 @@ BMallocIO::SetSize(off_t size)
} else { } else {
// size != 0, see, if necessary to resize // size != 0, see, if necessary to resize
size_t newSize = (size + fBlockSize - 1) / fBlockSize * fBlockSize; size_t newSize = (size + fBlockSize - 1) / fBlockSize * fBlockSize;
if (size != fMallocSize) { if (size != (off_t)fMallocSize) {
// we need to resize // we need to resize
if (char *newData = static_cast<char*>(realloc(fData, newSize))) { if (char *newData = static_cast<char*>(realloc(fData, newSize))) {
// set the new area to 0 // set the new area to 0
if (newSize > fMallocSize) if (newSize > fMallocSize)
memset(newData + fMallocSize, 0, newSize - fMallocSize); memset(newData + fMallocSize, 0, newSize - fMallocSize);
fData = newData; fData = newData;
fMallocSize = newSize; fMallocSize = newSize;
} else // couldn't alloc the memory } else // couldn't alloc the memory