Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/stdio implement EOVERFLOW



details:   https://anonhg.NetBSD.org/src/rev/59117567984d
branches:  trunk
changeset: 758153:59117567984d
user:      christos <christos%NetBSD.org@localhost>
date:      Fri Oct 22 21:29:45 2010 +0000

description:
implement EOVERFLOW

diffstat:

 lib/libc/stdio/ftell.c |  11 ++++++++---
 lib/libc/stdio/local.h |   8 +++++++-
 2 files changed, 15 insertions(+), 4 deletions(-)

diffs (57 lines):

diff -r f2c6257dc3ff -r 59117567984d lib/libc/stdio/ftell.c
--- a/lib/libc/stdio/ftell.c    Fri Oct 22 21:29:31 2010 +0000
+++ b/lib/libc/stdio/ftell.c    Fri Oct 22 21:29:45 2010 +0000
@@ -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 @@
        if (fp->_seek == NULL) {
                FUNLOCKFILE(fp);
                errno = ESPIPE;                 /* historic practice */
-               return (-1L);
+               return -1L;
        }
 
        /*
@@ -97,5 +97,10 @@
                pos += fp->_p - fp->_bf._base;
        }
        FUNLOCKFILE(fp);
+       if (_FPOS_OVERFLOW(pos)) {
+               errno = EOVERFLOW;
+               return -1L;
+       }
+               
        return (long)(pos);
 }
diff -r f2c6257dc3ff -r 59117567984d lib/libc/stdio/local.h
--- a/lib/libc/stdio/local.h    Fri Oct 22 21:29:31 2010 +0000
+++ b/lib/libc/stdio/local.h    Fri Oct 22 21:29:45 2010 +0000
@@ -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 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)



Home | Main Index | Thread Index | Old Index