bug-coreutils
[Top][All Lists]
Advanced

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

Re: FYI: portability tweak for Tru64 V4.0.


From: Jim Meyering
Subject: Re: FYI: portability tweak for Tru64 V4.0.
Date: Thu, 26 Oct 2006 15:16:33 +0200

Paul Eggert <address@hidden> wrote:

> Jim Meyering <address@hidden> writes:
>
>> +static inline off_t ftello (FILE *stream)
>> +{
>> +  off_t off = ftell (stream);
>> +  if (off < 0)
>> +    return off;
>> +  if (off != (long int) off)
>> +    {
>> +      errno = EOVERFLOW;
>> +      return -1;
>> +    }
>> +  return off;
>> +}
>
> Something's odd here.  ftell returns long int, so the ftello
> substitute needs to worry about overflow only on hosts where long int
> is wider than off_t.  But I don't know of any such hosts and don't
> expect that there will ever be any.  Surely on Tru64 both types are
> 64-bit.
>
> How about this alternative instead?
>
> static inline off_t
> ftello (FILE *stream)
> {
>   return ftell (stream);
> }

That sounds reasonable.
I'm keeping the size check in the form a compile-time assertion.
Thanks!

2006-10-26  Jim Meyering  <address@hidden>

        * src/system.h (ftello): Add a compile-time check for the highly
        unlikely condition of off_t narrower than long int, rather than
        handling it at run time.  Based on a patch from Paul Eggert.

diff --git a/src/system.h b/src/system.h
index efe9290..edb3ede 100644
--- a/src/system.h
+++ b/src/system.h
@@ -524,15 +524,8 @@ # endif
 # if ! defined ftello
 static inline off_t ftello (FILE *stream)
 {
-  off_t off = ftell (stream);
-  if (off < 0)
-    return off;
-  if (off != (long int) off)
-    {
-      errno = EOVERFLOW;
-      return -1;
-    }
-  return off;
+  verify (sizeof (long int) <= sizeof (off_t));
+  return ftell (stream);
 }
 # endif
 #endif




reply via email to

[Prev in Thread] Current Thread [Next in Thread]