* lib/ftell.c: Include <limits.h>.
(ftell): Don't assume wraparound signed arithmetic.
2011-07-24 Paul Eggert <eggert@cs.ucla.edu>
+ ftell: do not assume wraparound signed arithmetic
+ * lib/ftell.c: Include <limits.h>.
+ (ftell): Don't assume wraparound signed arithmetic.
+
* README: Modernize discussion of signed integers.
Assuming overflow wraparound is no longer safe.
Mention ones' complement and signed magnitude.
#include <stdio.h>
#include <errno.h>
+#include <limits.h>
/* Get off_t. */
#include <unistd.h>
{
/* Use the replacement ftello function with all its workarounds. */
off_t offset = ftello (fp);
- if (offset == (long)offset)
+ if (LONG_MIN <= offset && offset <= LONG_MAX)
return (long)offset;
else
{