Save work on low-level file I/O.

This commit is contained in:
Michael R Sweet
2021-04-26 10:42:01 -04:00
parent 253717248c
commit 11588ce2f5
6 changed files with 392 additions and 37 deletions

View File

@@ -16,10 +16,12 @@
# include "pdfio.h"
# include <stdarg.h>
# include <errno.h>
# include <fcntl.h>
# include <unistd.h>
# include <string.h>
# include <ctype.h>
# include <zlib.h>
//
@@ -56,11 +58,18 @@
struct _pdfio_file_s // PDF file structure
{
char *filename; // Filename
int fd; // File descriptor
const char *filename; // Filename
pdfio_mode_t mode; // Read/write mode
pdfio_error_cb_t error_cb; // Error callback
void *error_data; // Data for error callback
// Active file data
int fd; // File descriptor
char buffer[8192], // Read/write buffer
*bufptr, // Pointer into buffer
*bufend; // End of buffer
off_t bufpos; // Position in file for start of buffer
// Allocated data elements
size_t num_arrays, // Number of arrays
alloc_arrays; // Allocated arrays
@@ -81,9 +90,22 @@ struct _pdfio_obj_s // Object
pdfio_file_t *pdf; // PDF file
int number, // Number
generation; // Generation
off_t offset; // Offset in file
size_t length; // Length
off_t dict_offset, // Offset to dict in file
length_offset, // Offset to /Length in dict
stream_offset; // Offset to start of stream in file
size_t stream_length; // Length of stream, if any
pdfio_dict_t *dict; // Dictionary
pdfio_stream_t *stream; // Open stream, if any
};
struct _pdfio_stream_s // Stream
{
pdfio_file_t *pdf; // PDF file
pdfio_obj_t *obj; // Object
pdfio_filter_t filter; // Compression/decompression filter
char buffer[8192]; // Read/write buffer
size_t bufused; // Number of bytes in buffer
z_stream flate; // Flate filter state
};
typedef struct _pdfio_value_s // Value structure
@@ -109,15 +131,26 @@ typedef struct _pdfio_value_s // Value structure
extern void _pdfioArrayDelete(pdfio_array_t *a) PDFIO_INTERNAL;
extern _pdfio_value_t *_pdfioArrayGetValue(pdfio_array_t *a, size_t n) PDFIO_INTERNAL;
extern void _pdfioDictDelete(pdfio_dict_t *dict) PDFIO_INTERNAL;
extern _pdfio_value_t *_pdfioDictGetValue(pdfio_dict_t *dict, const char *key) PDFIO_INTERNAL;
extern bool _pdfioDictSetValue(pdfio_dict_t *dict, const char *key, _pdfio_value_t *value) PDFIO_INTERNAL;
extern bool _pdfioFileDefaultError(pdfio_file_t *pdf, const char *message, void *data) PDFIO_INTERNAL;
extern void _pdfioFileDelete(pdfio_file_t *file) PDFIO_INTERNAL;
extern void _pdfioFileDelete(pdfio_file_t *pdf) PDFIO_INTERNAL;
extern bool _pdfioFileError(pdfio_file_t *pdf, const char *format, ...) PDFIO_FORMAT(2,3) PDFIO_INTERNAL;
extern int _pdfioFileGetChar(pdfio_file_t *pdf) PDFIO_INTERNAL;
extern ssize_t _pdfioFileRead(pdfio_file_t *pdf, char *buffer, size_t bytes) PDFIO_INTERNAL;
extern off_t _pdfioFileSeek(pdfio_file_t *pdf, off_t offset, int whence) PDFIO_INTERNAL;
extern off_t _pdfioFileTell(pdfio_file_t *pdf) PDFIO_INTERNAL;
extern bool _pdfioFileWrite(pdfio_file_t *pdf, const char *buffer, size_t bytes) PDFIO_INTERNAL;
extern void _pdfioObjDelete(pdfio_obj_t *obj) PDFIO_INTERNAL;
extern void _pdfioStreamDelete(pdfio_stream_t *obj) PDFIO_INTERNAL;
extern bool _pdfioStringIsAllocated(pdfio_file_t *pdf, const char *s) PDFIO_INTERNAL;
extern void _pdfioValueDelete(_pdfio_value_t *v) PDFIO_INTERNAL;