From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id A9CE3385E037 for ; Fri, 7 Jul 2023 16:40:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A9CE3385E037 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1688748022; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=qQWZ29YbXP8da1/bbmbI5pkNfSStmru2JeDYdp1hoJ4=; b=H6dfsZgjLeNLKGwcE8e8drvyaw7kLouACwkjnXE86GeMGbQzN/jjXuRHIXQUnxzzsm1JHD AmM7BT0iZq58eP1f5/4IWjcmOSrSNj0B3m0pWktCBiUdyY1wSsskh2qERxgiRXuwXg2FQp 2iECWvrR4XH7itF1J8d96mZcm4uwaC4= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-19-EBz5VuOpO_etvRZk1zjH3g-1; Fri, 07 Jul 2023 12:40:20 -0400 X-MC-Unique: EBz5VuOpO_etvRZk1zjH3g-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 81E78856F66; Fri, 7 Jul 2023 16:40:20 +0000 (UTC) Received: from localhost (unknown [10.42.28.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id 488E9492B01; Fri, 7 Jul 2023 16:40:20 +0000 (UTC) From: Jonathan Wakely 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 Message-ID: <20230707164019.1537221-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: When this code was written we didn't have the 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 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::open): Use fopen unconditionally. (get_file_offset): Use lseek unconditionally. (__basic_file::seekoff): Likewise. (__basic_file::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 #include #include #include @@ -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::max() - || __off < numeric_limits::min()) + if _GLIBCXX17_CONSTEXPR (sizeof(streamoff) > sizeof(off_t)) + if (__off > numeric_limits::max() + || __off < numeric_limits::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::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