This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [RFC] Another look at LFS vs filebuf::showmanyc
Paolo Carlini wrote:
Nathan Myers wrote:
I agree. I see little benefit to ever returning a value bigger than
(say) 1M.
Good, thanks. I'm already testing a patch.
Ok, just tested the below both on x86 and x86-64. Also verified that 4
recent
glibcs (december 2003, january 2004, april 2004, june 2004) are ok wrt
to the
fstat64 visibility issue. I'm beginning to think that maybe, last time I
worked
on it, I did something wrong myself :( ...
Anyway, if nobody objects I'd like to apply the below to mainline real soon.
Thanks,
Paolo.
///////////////
2004-09-20 Paolo Carlini <pcarlini@suse.de>
PR libstdc++/12882 (cont)
* acinclude.m4 (GLIBCXX_CHECK_LFS): Check for fstat64 too.
* configure: Regenerate.
* config/io/basic_file_stdio.cc (__basic_file<>::showmanyc): When
_GLIBCXX_USE_LFS use fstat64 and lseek64, thus providing a non
trivial showmanyc for large files too.
diff -urN libstdc++-v3-orig/acinclude.m4 libstdc++-v3/acinclude.m4
--- libstdc++-v3-orig/acinclude.m4 2004-08-02 22:28:11.000000000 +0200
+++ libstdc++-v3/acinclude.m4 2004-09-20 20:13:45.000000000 +0200
@@ -573,12 +573,15 @@
AC_TRY_LINK(
[#include <unistd.h>
#include <stdio.h>
+ #include <sys/stat.h>
],
[FILE* fp;
fopen64("t", "w");
fseeko64(fp, 0, SEEK_CUR);
ftello64(fp);
- lseek64(1, 0, SEEK_CUR);],
+ lseek64(1, 0, SEEK_CUR);
+ struct stat64 buf;
+ fstat64(1, &buf);],
[glibcxx_cv_LFS=yes],
[glibcxx_cv_LFS=no])
])
diff -urN libstdc++-v3-orig/config/io/basic_file_stdio.cc libstdc++-v3/config/io/basic_file_stdio.cc
--- libstdc++-v3-orig/config/io/basic_file_stdio.cc 2004-09-16 18:04:21.000000000 +0200
+++ libstdc++-v3/config/io/basic_file_stdio.cc 2004-09-20 19:52:05.000000000 +0200
@@ -68,7 +68,7 @@
# endif
#endif
-#include <limits> // For <off_t>::max() and min()
+#include <limits> // For <off_t>::max() and min() and <streamsize>::max()
namespace __gnu_internal
{
@@ -315,8 +315,8 @@
#ifdef _GLIBCXX_USE_LFS
return lseek64(this->fd(), __off, __way);
#else
- if (__off > std::numeric_limits<off_t>::max()
- || __off < std::numeric_limits<off_t>::min())
+ if (__off > numeric_limits<off_t>::max()
+ || __off < numeric_limits<off_t>::min())
return -1L;
return lseek(this->fd(), __off, __way);
#endif
@@ -352,10 +352,21 @@
#if defined(_GLIBCXX_HAVE_S_ISREG) || defined(_GLIBCXX_HAVE_S_IFREG)
// Regular files.
+#ifdef _GLIBCXX_USE_LFS
+ struct stat64 __buffer;
+ const int __err = fstat64(this->fd(), &__buffer);
+ if (!__err && _GLIBCXX_ISREG(__buffer.st_mode))
+ {
+ const streamoff __off = __buffer.st_size - lseek64(this->fd(), 0,
+ ios_base::cur);
+ return std::min(__off, streamoff(numeric_limits<streamsize>::max()));
+ }
+#else
struct stat __buffer;
- int __ret = fstat(this->fd(), &__buffer);
- if (!__ret && _GLIBCXX_ISREG(__buffer.st_mode))
- return __buffer.st_size - lseek(this->fd(), 0, ios_base::cur);
+ const int __err = fstat(this->fd(), &__buffer);
+ if (!__err && _GLIBCXX_ISREG(__buffer.st_mode))
+ return __buffer.st_size - lseek(this->fd(), 0, ios_base::cur);
+#endif
#endif
return 0;
}