diff options
author | Werner Koch <[email protected]> | 2014-09-11 12:33:46 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2014-09-11 12:37:21 +0000 |
commit | 5a4684f3b0db4cd5c13f94b1319c245ef96ce91d (patch) | |
tree | eb3c5750c13c246b14ff2ed1646616face838be0 /src/estream.c | |
parent | Fix compiler warning for w32. (diff) | |
download | libgpg-error-5a4684f3b0db4cd5c13f94b1319c245ef96ce91d.tar.gz libgpg-error-5a4684f3b0db4cd5c13f94b1319c245ef96ce91d.zip |
Fix problems with ssize_t and off_t.
* configure.ac (AC_SYS_LARGEFILE): New.
(AC_CHECK_HEADERS): Check for stdint.h.
(AC_CHECK_SIZEOF): Add for int, long and long long.
(REPLACEMENT_FOR_OFF_T): New ac_define.
* src/mkheader.c (have_stdint_h, have_w32_system, have_w64_system)
(replacement_for_off_type, stdint_h_included): New.
(xfree, xstrdup): New.
(parse_config_h): New.
(write_special): Support "define:gpgrt_off_t", "define:gpgrt_ssize_t",
"api_ssize_t" tags.
(main): Add config.h arg. Call parse_config_h. Fix substitute code.
* src/Makefile.am (gpg-error.h): Pass config.h to mkheader.
* src/gpg-error.h.in: Include definitions for gpgrt_ssize_t and
gpgrt_off_t. Let mkheader insert ssize_t keywords. Chnage all off_t
to gpgrt_off_t.
* src/estream.c: Change all off_t to gpgrt_off_t. Chnage all ssize_t
to gpgrt_ssize_t.
* src/visibility.c (gpgrt_fseeko): Use gpgrt_off_t.
(gpgrt_ftello): Ditto.
(gpgrt_getline): Use gpgrt_ssize_t.
(gpgrt_read_line): Ditto.
Diffstat (limited to 'src/estream.c')
-rw-r--r-- | src/estream.c | 80 |
1 files changed, 41 insertions, 39 deletions
diff --git a/src/estream.c b/src/estream.c index 7a5646e..d16938e 100644 --- a/src/estream.c +++ b/src/estream.c @@ -165,7 +165,7 @@ struct _gpgrt_stream_internal void *opaque; /* Opaque data. */ unsigned int modeflags; /* Flags for the backend. */ char *printable_fname; /* Malloced filename for es_fname_get. */ - off_t offset; + gpgrt_off_t offset; gpgrt_cookie_read_function_t func_read; gpgrt_cookie_write_function_t func_write; gpgrt_cookie_seek_function_t func_seek; @@ -607,11 +607,11 @@ func_mem_create (void *_GPGRT__RESTRICT *_GPGRT__RESTRICT cookie, /* Read function for memory objects. */ -static ssize_t +static gpgrt_ssize_t es_func_mem_read (void *cookie, void *buffer, size_t size) { estream_cookie_mem_t mem_cookie = cookie; - ssize_t ret; + gpgrt_ssize_t ret; if (size > mem_cookie->data_len - mem_cookie->offset) size = mem_cookie->data_len - mem_cookie->offset; @@ -628,11 +628,11 @@ es_func_mem_read (void *cookie, void *buffer, size_t size) /* Write function for memory objects. */ -static ssize_t +static gpgrt_ssize_t es_func_mem_write (void *cookie, const void *buffer, size_t size) { estream_cookie_mem_t mem_cookie = cookie; - ssize_t ret; + gpgrt_ssize_t ret; size_t nleft; if (!size) @@ -715,10 +715,10 @@ es_func_mem_write (void *cookie, const void *buffer, size_t size) /* Seek function for memory objects. */ static int -es_func_mem_seek (void *cookie, off_t *offset, int whence) +es_func_mem_seek (void *cookie, gpgrt_off_t *offset, int whence) { estream_cookie_mem_t mem_cookie = cookie; - off_t pos_new; + gpgrt_off_t pos_new; switch (whence) { @@ -879,12 +879,12 @@ func_fd_create (void **cookie, int fd, unsigned int modeflags, int no_close) } /* Read function for fd objects. */ -static ssize_t +static gpgrt_ssize_t es_func_fd_read (void *cookie, void *buffer, size_t size) { estream_cookie_fd_t file_cookie = cookie; - ssize_t bytes_read; + gpgrt_ssize_t bytes_read; if (IS_INVALID_FD (file_cookie->fd)) { @@ -908,11 +908,11 @@ es_func_fd_read (void *cookie, void *buffer, size_t size) } /* Write function for fd objects. */ -static ssize_t +static gpgrt_ssize_t es_func_fd_write (void *cookie, const void *buffer, size_t size) { estream_cookie_fd_t file_cookie = cookie; - ssize_t bytes_written; + gpgrt_ssize_t bytes_written; if (IS_INVALID_FD (file_cookie->fd)) { @@ -937,10 +937,10 @@ es_func_fd_write (void *cookie, const void *buffer, size_t size) /* Seek function for fd objects. */ static int -es_func_fd_seek (void *cookie, off_t *offset, int whence) +es_func_fd_seek (void *cookie, gpgrt_off_t *offset, int whence) { estream_cookie_fd_t file_cookie = cookie; - off_t offset_new; + gpgrt_off_t offset_new; int err; if (IS_INVALID_FD (file_cookie->fd)) @@ -1039,11 +1039,11 @@ es_func_w32_create (void **cookie, HANDLE hd, } /* Read function for W32 handle objects. */ -static ssize_t +static gpgrt_ssize_t es_func_w32_read (void *cookie, void *buffer, size_t size) { estream_cookie_w32_t w32_cookie = cookie; - ssize_t bytes_read; + gpgrt_ssize_t bytes_read; if (w32_cookie->hd == INVALID_HANDLE_VALUE) { @@ -1081,11 +1081,11 @@ es_func_w32_read (void *cookie, void *buffer, size_t size) } /* Write function for W32 handle objects. */ -static ssize_t +static gpgrt_ssize_t es_func_w32_write (void *cookie, const void *buffer, size_t size) { estream_cookie_w32_t w32_cookie = cookie; - ssize_t bytes_written; + gpgrt_ssize_t bytes_written; if (w32_cookie->hd == INVALID_HANDLE_VALUE) { @@ -1118,7 +1118,7 @@ es_func_w32_write (void *cookie, const void *buffer, size_t size) /* Seek function for W32 handle objects. */ static int -es_func_w32_seek (void *cookie, off_t *offset, int whence) +es_func_w32_seek (void *cookie, gpgrt_off_t *offset, int whence) { estream_cookie_w32_t w32_cookie = cookie; DWORD method; @@ -1165,7 +1165,8 @@ es_func_w32_seek (void *cookie, off_t *offset, int whence) if (post_syscall_func) post_syscall_func (); #endif - *offset = (unsigned long long)newoff.QuadPart; + /* Note that gpgrt_off_t is always 64 bit. */ + *offset = (gpgrt_off_t)newoff.QuadPart; return 0; } @@ -1253,12 +1254,12 @@ func_fp_create (void **cookie, FILE *fp, } /* Read function for FILE* objects. */ -static ssize_t +static gpgrt_ssize_t es_func_fp_read (void *cookie, void *buffer, size_t size) { estream_cookie_fp_t file_cookie = cookie; - ssize_t bytes_read; + gpgrt_ssize_t bytes_read; if (file_cookie->fp) { @@ -1276,7 +1277,7 @@ es_func_fp_read (void *cookie, void *buffer, size_t size) } /* Write function for FILE* objects. */ -static ssize_t +static gpgrt_ssize_t es_func_fp_write (void *cookie, const void *buffer, size_t size) { estream_cookie_fp_t file_cookie = cookie; @@ -1319,7 +1320,7 @@ es_func_fp_write (void *cookie, const void *buffer, size_t size) /* Seek function for FILE* objects. */ static int -es_func_fp_seek (void *cookie, off_t *offset, int whence) +es_func_fp_seek (void *cookie, gpgrt_off_t *offset, int whence) { estream_cookie_fp_t file_cookie = cookie; long int offset_new; @@ -1592,7 +1593,7 @@ es_fill (estream_t stream) else { gpgrt_cookie_read_function_t func_read = stream->intern->func_read; - ssize_t ret; + gpgrt_ssize_t ret; ret = (*func_read) (stream->intern->cookie, stream->buffer, stream->buffer_size); @@ -1632,7 +1633,7 @@ es_flush (estream_t stream) { size_t bytes_written; size_t data_flushed; - ssize_t ret; + gpgrt_ssize_t ret; if (! func_write) { @@ -1649,7 +1650,8 @@ es_flush (estream_t stream) data_flushed = 0; err = 0; - while ((((ssize_t) (stream->data_offset - data_flushed)) > 0) && (! err)) + while ((((gpgrt_ssize_t) (stream->data_offset - data_flushed)) > 0) + && !err) { ret = (*func_write) (stream->intern->cookie, stream->buffer + data_flushed, @@ -1896,7 +1898,7 @@ es_read_nbf (estream_t _GPGRT__RESTRICT stream, { gpgrt_cookie_read_function_t func_read = stream->intern->func_read; size_t data_read; - ssize_t ret; + gpgrt_ssize_t ret; int err; data_read = 0; @@ -2077,12 +2079,12 @@ es_unreadn (estream_t _GPGRT__RESTRICT stream, /* Seek in STREAM. */ static int -es_seek (estream_t _GPGRT__RESTRICT stream, off_t offset, int whence, - off_t *_GPGRT__RESTRICT offset_new) +es_seek (estream_t _GPGRT__RESTRICT stream, gpgrt_off_t offset, int whence, + gpgrt_off_t *_GPGRT__RESTRICT offset_new) { gpgrt_cookie_seek_function_t func_seek = stream->intern->func_seek; int err, ret; - off_t off; + gpgrt_off_t off; if (! func_seek) { @@ -2142,7 +2144,7 @@ es_write_nbf (estream_t _GPGRT__RESTRICT stream, { gpgrt_cookie_write_function_t func_write = stream->intern->func_write; size_t data_written; - ssize_t ret; + gpgrt_ssize_t ret; int err; if (bytes_to_write && (! func_write)) @@ -2613,10 +2615,10 @@ es_set_buffering (estream_t _GPGRT__RESTRICT stream, } -static off_t +static gpgrt_off_t es_offset_calculate (estream_t stream) { - off_t offset; + gpgrt_off_t offset; offset = stream->intern->offset + stream->data_offset; if (offset < stream->unread_data_len) @@ -3496,7 +3498,7 @@ _gpgrt_fseek (estream_t stream, long int offset, int whence) int -_gpgrt_fseeko (estream_t stream, off_t offset, int whence) +_gpgrt_fseeko (estream_t stream, gpgrt_off_t offset, int whence) { int err; @@ -3521,10 +3523,10 @@ _gpgrt_ftell (estream_t stream) } -off_t +gpgrt_off_t _gpgrt_ftello (estream_t stream) { - off_t ret = -1; + gpgrt_off_t ret = -1; lock_stream (stream); ret = es_offset_calculate (stream); @@ -3748,7 +3750,7 @@ _gpgrt_fputs (const char *_GPGRT__RESTRICT s, estream_t _GPGRT__RESTRICT stream) } -ssize_t +gpgrt_ssize_t _gpgrt_getline (char *_GPGRT__RESTRICT *_GPGRT__RESTRICT lineptr, size_t *_GPGRT__RESTRICT n, estream_t _GPGRT__RESTRICT stream) { @@ -3799,7 +3801,7 @@ _gpgrt_getline (char *_GPGRT__RESTRICT *_GPGRT__RESTRICT lineptr, out: - return err ? err : (ssize_t)line_n; + return err ? err : (gpgrt_ssize_t)line_n; } @@ -3832,7 +3834,7 @@ _gpgrt_getline (char *_GPGRT__RESTRICT *_GPGRT__RESTRICT lineptr, allow the caller to append a CR,LF,Nul. The buffer should be released using gpgrt_free. */ -ssize_t +gpgrt_ssize_t _gpgrt_read_line (estream_t stream, char **addr_of_buffer, size_t *length_of_buffer, size_t *max_length) |