From patchwork Tue Apr 2 04:07:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rosen Penev X-Patchwork-Id: 1073749 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=uclibc.org (client-ip=140.211.166.133; helo=hemlock.osuosl.org; envelope-from=uclibc-bounces@uclibc.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Jxkif/wH"; dkim-atps=neutral Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44YG015G2vz9sSG for ; Tue, 2 Apr 2019 15:08:00 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 8FECB86EC0; Tue, 2 Apr 2019 04:07:56 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id i3NrD9pr87fp; Tue, 2 Apr 2019 04:07:55 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by hemlock.osuosl.org (Postfix) with ESMTP id 24B5B86CE0; Tue, 2 Apr 2019 04:07:55 +0000 (UTC) X-Original-To: uclibc@lists.busybox.net Delivered-To: uclibc@osuosl.org Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by ash.osuosl.org (Postfix) with ESMTP id 4C6E61BF35E for ; Tue, 2 Apr 2019 04:07:54 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 496662261A for ; Tue, 2 Apr 2019 04:07:54 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id y4AYPyeMsYar for ; Tue, 2 Apr 2019 04:07:53 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by silver.osuosl.org (Postfix) with ESMTPS id A4D0222246 for ; Tue, 2 Apr 2019 04:07:53 +0000 (UTC) Received: by mail-pl1-f174.google.com with SMTP id d1so3860831plj.8 for ; Mon, 01 Apr 2019 21:07:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=FlGZePIm5OgGYx3YywLCiwbMrzRe1QIabJzn82bW0O4=; b=Jxkif/wHALUyd3OjErbuYRQVVNbnxBNDy0Qq+KOlOompWERjM1MOYlRnnGrpW/wKfv KoCGs9l62GOrW+IqsuE0rYhOpm6qNPTISwHi92/pZNgCn0SKzNIPulb3oXL1GxxFI2sN UFzOxC7ulnEfp500KBIzwCqGv4geZ1Q2XAg+sQp8MIhF/DS0kMqMaQ/4+gEazqDj3c4a Sv5N8cf83MgtbfvYbDEdf/z/7xkCOZsZsausFjRFsR5O4juo84hS+PbMLGdwSwrLBKtc UNDbksHHJAOWX3ones4+lUzmremPdHe7O71Nl/DHwZC7DSmAGykqtHkdY7n4wLSiERu9 nMXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=FlGZePIm5OgGYx3YywLCiwbMrzRe1QIabJzn82bW0O4=; b=c+w+BkWJ2dHIv3IDXKl941LZpY8/KC9OHn6RtPfurgBr81JS3AnvihLA0StKyIHcyd 3+y53oRqiTZzULImoaFXYRRYD2KQkaadoyELxi2pN9TYQRR4tRks2iK8rZVjOfXBXKHM 9yg8Dsotb0wkZFE0bUZnIBU6acL2Hg9+2oD7txac4SRJIIb5tHWN/FmNFkNVkwGAKwB/ aLg5BMzfgertxIA8oz4waJu2P5bnAcOBbRYuUbg73SC5oyi3vF36g3Be947+OK5gTw6M ZiKPSBQdbUIvhyYQKTLkjHV5moQWq/q8+cSiybJDf+B+AR3jm6D6p4JLChTQn1mFqo3/ NI8g== X-Gm-Message-State: APjAAAUSe5SDUyJcx/n8ZeNfllkr3rwTS5s/5wUqVBDrR8WkVNsbLs32 d13d9vCb82dGqpRiLdyXi9E1Wg5P5BE= X-Google-Smtp-Source: APXvYqw/eMKLBOWU8KTrSp+kjnt4tysLE9N0sNylNV2fuJ3HnyoX/lnaPPh5fxv09felrHfi0M4Hfg== X-Received: by 2002:a17:902:988e:: with SMTP id s14mr55372190plp.167.1554178072906; Mon, 01 Apr 2019 21:07:52 -0700 (PDT) Received: from mangix-pc.lan (astound-69-42-18-19.ca.astound.net. [69.42.18.19]) by smtp.gmail.com with ESMTPSA id i126sm16274697pfb.15.2019.04.01.21.07.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 01 Apr 2019 21:07:52 -0700 (PDT) From: Rosen Penev To: uclibc@uclibc.org Subject: [PATCH] stream: Add support for 64-bit integers Date: Mon, 1 Apr 2019 21:07:50 -0700 Message-Id: <20190402040750.304-1-rosenp@gmail.com> X-Mailer: git-send-email 2.17.1 X-BeenThere: uclibc@uclibc.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Discussion and development of uClibc \(the embedded C library\)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: uclibc-bounces@uclibc.org Sender: "uClibc" Many programs like gptfdisk or powertop try to use 64-bit integers with streams. This adds support for them. Signed-off-by: Rosen Penev --- include/istream | 21 ++++++++++++++++ include/istream_helpers | 55 +++++++++++++++++++++++++++++++++++++++++ include/ostream | 20 +++++++++++++++ tests/sstreamtest.cpp | 10 +++++++- 4 files changed, 105 insertions(+), 1 deletion(-) diff --git a/include/istream b/include/istream index 850ac30..afcaa5b 100644 --- a/include/istream +++ b/include/istream @@ -72,6 +72,11 @@ namespace std{ basic_istream& operator>>(void*& p); basic_istream& operator>>(basic_streambuf* sb); +#ifndef __STRICT_ANSI__ + basic_istream& operator>>(long long& n); + basic_istream& operator>>(unsigned long long& n); +#endif + #ifdef __UCLIBCXX_HAS_FLOATS__ basic_istream& operator>>(float& f); basic_istream& operator>>(double& f); @@ -450,6 +455,22 @@ namespace std{ return *this; } +#ifndef __STRICT_ANSI__ + template _UCXXEXPORT basic_istream& + basic_istream::operator>>(long long& n) + { + sentry(*this); + __istream_readin::readin(*this, n); + return *this; + } + template _UCXXEXPORT basic_istream& + basic_istream::operator>>(unsigned long long& n) + { + sentry(*this); + __istream_readin::readin(*this, n); + return *this; + } +#endif #ifdef __UCLIBCXX_HAS_FLOATS__ template _UCXXEXPORT basic_istream& basic_istream::operator>>(float& n) diff --git a/include/istream_helpers b/include/istream_helpers index 588df7f..d87e0c7 100644 --- a/include/istream_helpers +++ b/include/istream_helpers @@ -301,6 +301,61 @@ namespace std{ }; +#ifndef __STRICT_ANSI__ + template class _UCXXEXPORT __istream_readin{ + public: + inline static void readin(basic_istream& stream, long long & var) + { + basic_string temp; + + if(stream.flags() & ios_base::dec){ + temp = _readTokenDecimal( stream); + sscanf(temp.c_str(), "%lld", &var ); + }else{ + temp = _readToken( stream); + if( stream.flags() & ios_base::oct){ + sscanf(temp.c_str(), "%llo", (unsigned long long *)&var ); + }else if(stream.flags() & ios_base::hex){ + if(stream.flags() & ios_base::uppercase){ + scanf(temp.c_str(), "%llX", (unsigned long long *)&var ); + }else{ + sscanf(temp.c_str(), "%llx", (unsigned long long *)&var); + } + }else{ + sscanf(temp.c_str(), "%lli", (&var) ); + } + } + } + }; + + + template class _UCXXEXPORT __istream_readin{ + public: + inline static void readin(basic_istream& stream, unsigned long long & var) + { + basic_string temp; + + if(stream.flags() & ios_base::dec){ + temp = _readTokenDecimal( stream); + sscanf(temp.c_str(), "%llu", &var ); + }else{ + temp = _readToken( stream); + if( stream.flags() & ios_base::oct){ + sscanf(temp.c_str(), "%llo", &var ); + }else if(stream.flags() & ios_base::hex){ + if(stream.flags() & ios_base::uppercase){ + scanf(temp.c_str(), "%llX", &var ); + }else{ + sscanf(temp.c_str(), "%llx", &var); + } + }else{ + sscanf(temp.c_str(), "%lli", (long long *)(&var) ); + } + } + } + }; +#endif + #ifdef __UCLIBCXX_HAS_FLOATS__ template class _UCXXEXPORT __istream_readin{ diff --git a/include/ostream b/include/ostream index b112e94..289514c 100644 --- a/include/ostream +++ b/include/ostream @@ -85,6 +85,10 @@ namespace std { basic_ostream& operator<<(long double f); basic_ostream& operator<<(void* p); basic_ostream& operator<<(basic_streambuf* sb); +#ifndef __STRICT_ANSI__ + basic_ostream& operator<<(long long n); + basic_ostream& operator<<(unsigned long long n); +#endif _UCXXEXPORT basic_ostream& put(char_type c){ if(basic_ostream::traits_type::eq_int_type( @@ -217,6 +221,22 @@ namespace std { return *this; } +#ifndef __STRICT_ANSI__ + template _UCXXEXPORT basic_ostream& basic_ostream::operator<<(long long n) + { + sentry s(*this); + __ostream_printout::printout(*this, n); + return *this; + } + + template _UCXXEXPORT basic_ostream& basic_ostream::operator<<(unsigned long long n) + { + sentry s(*this); + __ostream_printout::printout(*this, n); + return *this; + } +#endif + template _UCXXEXPORT basic_ostream& basic_ostream::operator<<(float f){ sentry s(*this); __ostream_printout::printout(*this, f); diff --git a/tests/sstreamtest.cpp b/tests/sstreamtest.cpp index df3d521..7543ee3 100644 --- a/tests/sstreamtest.cpp +++ b/tests/sstreamtest.cpp @@ -9,6 +9,9 @@ int main(){ int i; std::string s; char c; +#ifndef __STRICT_ANSI__ + long long ll; +#endif a << "Starting testing "; a << 2 ; @@ -28,9 +31,14 @@ int main(){ +#ifndef __STRICT_ANSI__ + a.str("55 2.35 5 Test"); + a >> ll >> f >> i >> s; + std::cout << "ll (should be 55): " << ll << std::endl; +#else a.str("2.35 5 Test"); - a >> f >> i >> s; +#endif std::cout << "f (should be 2.35): " << f << std::endl; std::cout << "i (should be 5): " << i << std::endl;