public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: [PATCH] libstdc++: Compile basic_file_stdio.cc for LFS
Date: Fri,  7 Jul 2023 17:38:22 +0100	[thread overview]
Message-ID: <20230707164019.1537221-1-jwakely@redhat.com> (raw)

When this code was written we didn't have the <bits/largefile-config.h>
header, so it conditionally used lseek64 etc.

Since this is compiled into the library, not inline code in headers, we
can just define the relevant macros to get a 64-bit off_t and then
simplify the code.

Tested x86_64-linux. I intend to commit this next week.

-- >8 --

Instead of using fopen64, lseek64, and fstat64 we can just include
<bits/largefile-config.h> which defines _FILE_OFFSET_BITS=64 (and
similar target-specific macros). Then we can just use fopen, lseek and
fstat as normal, and they'll be the LFS versions if supported by the
target.

libstdc++-v3/ChangeLog:

	* config/io/basic_file_stdio.cc: Define LFS macros.
	(__basic_file<char>::open): Use fopen unconditionally.
	(get_file_offset): Use lseek unconditionally.
	(__basic_file<char>::seekoff): Likewise.
	(__basic_file<char>::showmanyc): Use fstat unconditionally.
---
 libstdc++-v3/config/io/basic_file_stdio.cc | 25 ++++++----------------
 1 file changed, 6 insertions(+), 19 deletions(-)

diff --git a/libstdc++-v3/config/io/basic_file_stdio.cc b/libstdc++-v3/config/io/basic_file_stdio.cc
index 27c2ad2afe3..7b1729a798f 100644
--- a/libstdc++-v3/config/io/basic_file_stdio.cc
+++ b/libstdc++-v3/config/io/basic_file_stdio.cc
@@ -26,6 +26,7 @@
 // ISO C++ 14882: 27.8  File-based streams
 //
 
+#include <bits/largefile-config.h>
 #include <bits/basic_file.h>
 #include <fcntl.h>
 #include <errno.h>
@@ -251,11 +252,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     const char* __c_mode = fopen_mode(__mode);
     if (__c_mode && !this->is_open())
       {
-#ifdef _GLIBCXX_USE_LFS
-	if ((_M_cfile = fopen64(__name, __c_mode)))
-#else
 	if ((_M_cfile = fopen(__name, __c_mode)))
-#endif
 	  {
 	    _M_cfile_created = true;
 	    __ret = this;
@@ -389,8 +386,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 # else
       return ftell(__f->file());
 # endif
-#elif defined(_GLIBCXX_USE_LFS)
-      return lseek64(__f->fd(), 0, (int)ios_base::cur);
 #else
       return lseek(__f->fd(), 0, (int)ios_base::cur);
 #endif
@@ -417,11 +412,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	  return -1;
       }
     return __way == ios_base::beg ? __off : std::get_file_offset(this);
-#elif defined(_GLIBCXX_USE_LFS)
-    return lseek64(this->fd(), __off, __way);
 #else
-    if (__off > numeric_limits<off_t>::max()
-	  || __off < numeric_limits<off_t>::min())
+    if _GLIBCXX17_CONSTEXPR (sizeof(streamoff) > sizeof(off_t))
+      if (__off > numeric_limits<off_t>::max()
+	    || __off < numeric_limits<off_t>::min())
       return -1L;
     return lseek(this->fd(), __off, __way);
 #endif
@@ -455,20 +449,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
 #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);
+    struct stat __buffer;
+    const int __err = fstat(this->fd(), &__buffer);
     if (!__err && _GLIBCXX_ISREG(__buffer.st_mode))
       {
 	const streamoff __off = __buffer.st_size - std::get_file_offset(this);
 	return std::min(__off, streamoff(numeric_limits<streamsize>::max()));
       }
-#else
-    struct stat __buffer;
-    const int __err = fstat(this->fd(), &__buffer);
-    if (!__err && _GLIBCXX_ISREG(__buffer.st_mode))
-      return __buffer.st_size - std::get_file_offset(this);
-#endif
 #endif
     return 0;
   }
-- 
2.41.0


                 reply	other threads:[~2023-07-07 16:40 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230707164019.1537221-1-jwakely@redhat.com \
    --to=jwakely@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=libstdc++@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).