Fix loading of last 1024 bytes for small PDF files (Issue #87)

This commit is contained in:
Michael R Sweet 2025-01-17 16:58:33 -05:00
parent 3bc041e6d3
commit 026f653e07
No known key found for this signature in database
GPG Key ID: BE67C75EC81F3244
2 changed files with 6 additions and 2 deletions

View File

@ -7,6 +7,7 @@ v1.4.1 - YYYY-MM-DD
- Fixed the link libraries for the example source code (Issue #86)
- Fixed handling of the Info object (Issue #87)
- Fixed opening of PDF files less than 1024 bytes in length (Issue #87)
v1.4.0 - 2024-12-26

View File

@ -1,7 +1,7 @@
//
// Common support functions for pdfio.
//
// Copyright © 2021-2024 by Michael R Sweet.
// Copyright © 2021-2025 by Michael R Sweet.
//
// Licensed under Apache License v2.0. See the file "LICENSE" for more
// information.
@ -398,7 +398,10 @@ _pdfioFileSeek(pdfio_file_t *pdf, // I - PDF file
}
// Seek within the file...
if ((offset = lseek(pdf->fd, offset, whence)) < 0)
if ((offset = lseek(pdf->fd, offset, whence)) < 0 && whence == SEEK_END && errno == EINVAL)
offset = lseek(pdf->fd, 0, SEEK_SET);
if (offset < 0)
{
_pdfioFileError(pdf, "Unable to seek within file - %s", strerror(errno));
return (-1);