diff options
| author | christos <christos@NetBSD.org> | 2010-10-22 21:29:45 +0000 |
|---|---|---|
| committer | christos <christos@NetBSD.org> | 2010-10-22 21:29:45 +0000 |
| commit | ec053f73a0ce37daf4abd8973bdf72644ee53da3 (patch) | |
| tree | 0717d0c48c1209466e3c1ce74f7b30bb77136df6 /lib/libc/stdio | |
| parent | 603e33ef3283f4db07faaa12957ea90e0bef909d (diff) | |
implement EOVERFLOW
Diffstat (limited to 'lib/libc/stdio')
| -rw-r--r-- | lib/libc/stdio/ftell.c | 11 | ||||
| -rw-r--r-- | lib/libc/stdio/local.h | 8 |
2 files changed, 15 insertions, 4 deletions
diff --git a/lib/libc/stdio/ftell.c b/lib/libc/stdio/ftell.c index 1ba95da2b9b..ff06b63eaa6 100644 --- a/lib/libc/stdio/ftell.c +++ b/lib/libc/stdio/ftell.c @@ -1,4 +1,4 @@ -/* $NetBSD: ftell.c,v 1.15 2003/08/07 16:43:25 agc Exp $ */ +/* $NetBSD: ftell.c,v 1.16 2010/10/22 21:29:45 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)ftell.c 8.2 (Berkeley) 5/4/95"; #else -__RCSID("$NetBSD: ftell.c,v 1.15 2003/08/07 16:43:25 agc Exp $"); +__RCSID("$NetBSD: ftell.c,v 1.16 2010/10/22 21:29:45 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -62,7 +62,7 @@ ftell(fp) if (fp->_seek == NULL) { FUNLOCKFILE(fp); errno = ESPIPE; /* historic practice */ - return (-1L); + return -1L; } /* @@ -97,5 +97,10 @@ ftell(fp) pos += fp->_p - fp->_bf._base; } FUNLOCKFILE(fp); + if (_FPOS_OVERFLOW(pos)) { + errno = EOVERFLOW; + return -1L; + } + return (long)(pos); } diff --git a/lib/libc/stdio/local.h b/lib/libc/stdio/local.h index 8bffaa0602a..b2cbf0e6e50 100644 --- a/lib/libc/stdio/local.h +++ b/lib/libc/stdio/local.h @@ -1,4 +1,4 @@ -/* $NetBSD: local.h,v 1.25 2010/09/06 14:52:55 christos Exp $ */ +/* $NetBSD: local.h,v 1.26 2010/10/22 21:29:45 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -113,3 +113,9 @@ extern int __vfwscanf_unlocked __P((FILE * __restrict, extern void __flockfile_internal __P((FILE *, int)); extern void __funlockfile_internal __P((FILE *, int)); + +/* + * Detect if the current file position fits in a long int. + */ +#define _FPOS_OVERFLOW(pos) (sizeof(fpos_t) != sizeof(long) && \ + ((pos) & (~0ULL << ((sizeof(fpos_t) - sizeof(long)) * NBBY))) != 0) |
