diff options
author | Matthew Dempsky <matthew@cvs.openbsd.org> | 2012-05-21 22:24:20 +0000 |
---|---|---|
committer | Matthew Dempsky <matthew@cvs.openbsd.org> | 2012-05-21 22:24:20 +0000 |
commit | b15dbd3eb0380f89ab5b2fce55432ff4e993a48c (patch) | |
tree | 963e28e60df6008bf1b031ed8c1befa6cfd3f1c9 /lib/libc | |
parent | c3af4dac8c2adc170d3657f12942d3d140fc5e58 (diff) |
Fix ftell() to return EOVERFLOW if the file offset is greater than
LONG_MAX. Also, remove an Alpha-specific optimization that only saves
a couple of bytes of code size.
ok millert, guenther
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/stdio/fseek.c | 13 | ||||
-rw-r--r-- | lib/libc/stdio/ftell.c | 20 |
2 files changed, 10 insertions, 23 deletions
diff --git a/lib/libc/stdio/fseek.c b/lib/libc/stdio/fseek.c index 0b3dce3ff22..cdd40b62f8a 100644 --- a/lib/libc/stdio/fseek.c +++ b/lib/libc/stdio/fseek.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fseek.c,v 1.10 2009/11/09 00:18:27 kurt Exp $ */ +/* $OpenBSD: fseek.c,v 1.11 2012/05/21 22:24:19 matthew Exp $ */ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -244,17 +244,8 @@ dumb: return (0); } -/* - * fseek()'s offset is a long and sizeof(off_t) != sizeof(long) on all arches - */ -#if defined(__alpha__) && defined(__indr_reference) -__indr_reference(fseeko, fseek); -#else int fseek(FILE *fp, long offset, int whence) { - off_t off = offset; - - return(fseeko(fp, off, whence)); + return (fseeko(fp, offset, whence)); } -#endif diff --git a/lib/libc/stdio/ftell.c b/lib/libc/stdio/ftell.c index 0a22a14451c..0a2016ce10b 100644 --- a/lib/libc/stdio/ftell.c +++ b/lib/libc/stdio/ftell.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ftell.c,v 1.9 2009/11/09 00:18:27 kurt Exp $ */ +/* $OpenBSD: ftell.c,v 1.10 2012/05/21 22:24:19 matthew Exp $ */ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -33,6 +33,7 @@ #include <stdio.h> #include <errno.h> +#include <limits.h> #include "local.h" /* @@ -83,18 +84,13 @@ out: FUNLOCKFILE(fp); return (pos); } -/* - * ftell() returns a long and sizeof(off_t) != sizeof(long) on all arches - */ -#if defined(__alpha__) && defined(__indr_reference) -__indr_reference(ftello, ftell); -#else long ftell(FILE *fp) { - long pos; - - pos = (long)ftello(fp); - return(pos); + off_t offset = ftello(fp); + if (offset > LONG_MAX) { + errno = EOVERFLOW; + return (-1); + } + return ((long)offset); } -#endif |