diff options
Diffstat (limited to 'gl/ftello.c')
| -rw-r--r-- | gl/ftello.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/gl/ftello.c b/gl/ftello.c index 64119aab..e4f96d1a 100644 --- a/gl/ftello.c +++ b/gl/ftello.c | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* An ftello() function that works around platform bugs. | 1 | /* An ftello() function that works around platform bugs. |
| 2 | Copyright (C) 2007, 2009-2024 Free Software Foundation, Inc. | 2 | Copyright (C) 2007, 2009-2026 Free Software Foundation, Inc. |
| 3 | 3 | ||
| 4 | This file is free software: you can redistribute it and/or modify | 4 | This file is free software: you can redistribute it and/or modify |
| 5 | it under the terms of the GNU Lesser General Public License as | 5 | it under the terms of the GNU Lesser General Public License as |
| @@ -20,7 +20,7 @@ | |||
| 20 | #include <stdio.h> | 20 | #include <stdio.h> |
| 21 | 21 | ||
| 22 | #include <errno.h> | 22 | #include <errno.h> |
| 23 | #include "intprops.h" | 23 | #include <stdckdint.h> |
| 24 | 24 | ||
| 25 | /* Get lseek. */ | 25 | /* Get lseek. */ |
| 26 | #include <unistd.h> | 26 | #include <unistd.h> |
| @@ -34,7 +34,10 @@ ftello (FILE *fp) | |||
| 34 | # undef ftell | 34 | # undef ftell |
| 35 | # define ftello ftell | 35 | # define ftello ftell |
| 36 | #endif | 36 | #endif |
| 37 | #if _GL_WINDOWS_64_BIT_OFF_T | 37 | #if (defined _WIN32 && !defined __CYGWIN__) \ |
| 38 | /* We need to test _FILE_OFFSET_BITS for mingw-w64 */ \ | ||
| 39 | /* and _GL_WINDOWS_64_BIT_OFF_T for MSVC. */ \ | ||
| 40 | && (_FILE_OFFSET_BITS == 64 || _GL_WINDOWS_64_BIT_OFF_T) | ||
| 38 | # undef ftello | 41 | # undef ftello |
| 39 | # if HAVE__FTELLI64 /* msvc, mingw64 */ | 42 | # if HAVE__FTELLI64 /* msvc, mingw64 */ |
| 40 | # define ftello _ftelli64 | 43 | # define ftello _ftelli64 |
| @@ -97,7 +100,7 @@ ftello (FILE *fp) | |||
| 97 | 100 | ||
| 98 | /* Compute pos + buffered, with overflow check. */ | 101 | /* Compute pos + buffered, with overflow check. */ |
| 99 | off_t sum; | 102 | off_t sum; |
| 100 | if (! INT_ADD_OK (pos, buffered, &sum)) | 103 | if (ckd_add (&sum, pos, buffered)) |
| 101 | { | 104 | { |
| 102 | errno = EOVERFLOW; | 105 | errno = EOVERFLOW; |
| 103 | return -1; | 106 | return -1; |
| @@ -121,13 +124,11 @@ ftello (FILE *fp) | |||
| 121 | gets confused by this. */ | 124 | gets confused by this. */ |
| 122 | if (fp_->_flag & _IOWRT) | 125 | if (fp_->_flag & _IOWRT) |
| 123 | { | 126 | { |
| 124 | off_t pos; | ||
| 125 | |||
| 126 | /* Call ftello nevertheless, for the side effects that it does on fp. */ | 127 | /* Call ftello nevertheless, for the side effects that it does on fp. */ |
| 127 | ftello (fp); | 128 | ftello (fp); |
| 128 | 129 | ||
| 129 | /* Compute the file position ourselves. */ | 130 | /* Compute the file position ourselves. */ |
| 130 | pos = lseek (fileno (fp), (off_t) 0, SEEK_CUR); | 131 | off_t pos = lseek (fileno (fp), (off_t) 0, SEEK_CUR); |
| 131 | if (pos >= 0) | 132 | if (pos >= 0) |
| 132 | { | 133 | { |
| 133 | if ((fp_->_flag & _IONBF) == 0 && fp_->_base != NULL) | 134 | if ((fp_->_flag & _IONBF) == 0 && fp_->_base != NULL) |
