Skip to content

Commit

Permalink
read/write in chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
Cristy committed Jul 31, 2024
1 parent e7a3269 commit 16bf20f
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions magick/blob.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ MagickExport MagickBooleanType BlobToFile(char *filename,const void *blob,
for (i=0; i < length; i+=(size_t) count)
{
count=write(file,(const char *) blob+i,MagickMin(length-i,(size_t)
MAGICK_SSIZE_MAX));
MagickMaxBufferExtent));
if (count <= 0)
{
count=0;
Expand Down Expand Up @@ -1235,7 +1235,7 @@ MagickExport unsigned char *FileToBlob(const char *filename,const size_t extent,
for (i=0; i < *length; i+=count)
{
count=read(file,blob+i,(size_t) MagickMin(*length-i,(size_t)
MAGICK_SSIZE_MAX));
MagickMaxBufferExtent));
if (count <= 0)
{
count=0;
Expand Down
2 changes: 1 addition & 1 deletion magick/blob.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
extern "C" {
#endif

#define MagickMaxBufferExtent 81920
#define MagickMaxBufferExtent 524288
#define MagickMinBufferExtent 16384

typedef enum
Expand Down
8 changes: 4 additions & 4 deletions magick/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -3800,10 +3800,10 @@ static inline MagickOffsetType WritePixelCacheRegion(
{
#if !defined(MAGICKCORE_HAVE_PWRITE)
count=write(cache_info->file,buffer+i,(size_t) MagickMin(length-
(MagickSizeType) i,MAGICK_SSIZE_MAX));
(MagickSizeType) i,MagickMaxBufferExtent));
#else
count=pwrite(cache_info->file,buffer+i,(size_t) MagickMin(length-
(MagickSizeType) i,MAGICK_SSIZE_MAX),offset+i);
(MagickSizeType) i,MagickMaxBufferExtent),offset+i);
#endif
if (count <= 0)
{
Expand Down Expand Up @@ -4629,10 +4629,10 @@ static inline MagickOffsetType ReadPixelCacheRegion(
{
#if !defined(MAGICKCORE_HAVE_PREAD)
count=read(cache_info->file,buffer+i,(size_t) MagickMin(length-
(MagickSizeType) i,(size_t) MAGICK_SSIZE_MAX));
(MagickSizeType) i,(size_t) MagickMaxBufferExtent));
#else
count=pread(cache_info->file,buffer+i,(size_t) MagickMin(length-
(MagickSizeType) i,(size_t) MAGICK_SSIZE_MAX),offset+i);
(MagickSizeType) i,(size_t) MagickMaxBufferExtent),offset+i);
#endif
if (count <= 0)
{
Expand Down
4 changes: 2 additions & 2 deletions magick/distribute-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ static inline MagickOffsetType dpc_read(int file,const MagickSizeType length,
for (i=0; i < (MagickOffsetType) length; i+=count)
{
count=recv(file,(char *) message+i,(LENGTH_TYPE) MagickMin(length-i,
(MagickSizeType) MAGICK_SSIZE_MAX),0);
(MagickSizeType) MagickMaxBufferExtent),0);
if (count <= 0)
{
count=0;
Expand Down Expand Up @@ -455,7 +455,7 @@ static inline MagickOffsetType dpc_send(int file,const MagickSizeType length,
for (i=0; i < (MagickOffsetType) length; i+=count)
{
count=(MagickOffsetType) send(file,(char *) message+i,(LENGTH_TYPE)
MagickMin(length-i,(MagickSizeType) MAGICK_SSIZE_MAX),MSG_NOSIGNAL);
MagickMin(length-i,(MagickSizeType) MagickMaxBufferExtent),MSG_NOSIGNAL);
if (count <= 0)
{
count=0;
Expand Down
8 changes: 4 additions & 4 deletions magick/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ static inline MagickOffsetType WriteMatrixElements(
{
#if !defined(MAGICKCORE_HAVE_PWRITE)
count=write(matrix_info->file,buffer+i,(size_t) MagickMin(length-i,
(MagickSizeType) MAGICK_SSIZE_MAX));
(MagickSizeType) MagickMaxBufferExtent));
#else
count=pwrite(matrix_info->file,buffer+i,(size_t) MagickMin(length-i,
(MagickSizeType) MAGICK_SSIZE_MAX),(off_t) (offset+i));
(MagickSizeType) MagickMaxBufferExtent),(off_t) (offset+i));
#endif
if (count <= 0)
{
Expand Down Expand Up @@ -683,10 +683,10 @@ static inline MagickOffsetType ReadMatrixElements(
{
#if !defined(MAGICKCORE_HAVE_PREAD)
count=read(matrix_info->file,buffer+i,(size_t) MagickMin(length-i,
(MagickSizeType) MAGICK_SSIZE_MAX));
(MagickSizeType) MagickMaxBufferExtent));
#else
count=pread(matrix_info->file,buffer+i,(size_t) MagickMin(length-i,
(MagickSizeType) MAGICK_SSIZE_MAX),(off_t) (offset+i));
(MagickSizeType) MagickMaxBufferExtent),(off_t) (offset+i));
#endif
if (count <= 0)
{
Expand Down
2 changes: 1 addition & 1 deletion magick/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ MagickExport StringInfo *ConfigureFileToStringInfo(const char *filename)
for (i=0; i < length; i+=count)
{
count=read(file,string+i,(size_t) MagickMin(length-i,(size_t)
MAGICK_SSIZE_MAX));
MagickMaxBufferExtent));
if (count <= 0)
{
count=0;
Expand Down
2 changes: 1 addition & 1 deletion magick/xml-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ MagickPrivate char *FileToXML(const char *filename,const size_t extent)
(void) lseek(file,0,SEEK_SET);
for (i=0; i < length; i+=count)
{
count=read(file,xml+i,(size_t) MagickMin(length-i,(size_t) MAGICK_SSIZE_MAX));
count=read(file,xml+i,(size_t) MagickMin(length-i,(size_t) MagickMaxBufferExtent));
if (count <= 0)
{
count=0;
Expand Down

0 comments on commit 16bf20f

Please sign in to comment.