From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04on2054.outbound.protection.outlook.com [40.107.8.54]) by sourceware.org (Postfix) with ESMTPS id 4E9AE3850F39 for ; Fri, 23 Dec 2022 14:59:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4E9AE3850F39 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=44Nqj/4bHgphtluox1yzY0GbKckVJnkBppp2LbMUctI=; b=t4y867m2xZcIYvHGW6JIC7X+C7J8dTVp5O964leHDRQm4XpbKW8LzT7HEiyOIHfUlL9FkyAO7gX5paMv7RaIE9VIsD9BffLkNIv23aYEB0HIcP3VLcFiJ/sVyzbK0NG8penusyiFNLkCDLgDRIkfNrItP3WEsz6eGW9z/SV3/z8= Received: from AS9PR06CA0129.eurprd06.prod.outlook.com (2603:10a6:20b:467::7) by DU0PR08MB7764.eurprd08.prod.outlook.com (2603:10a6:10:3b8::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5944.6; Fri, 23 Dec 2022 14:59:36 +0000 Received: from AM7EUR03FT060.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:467:cafe::85) by AS9PR06CA0129.outlook.office365.com (2603:10a6:20b:467::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5944.13 via Frontend Transport; Fri, 23 Dec 2022 14:59:36 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM7EUR03FT060.mail.protection.outlook.com (100.127.140.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5944.13 via Frontend Transport; Fri, 23 Dec 2022 14:59:35 +0000 Received: ("Tessian outbound baf1b7a96f25:v132"); Fri, 23 Dec 2022 14:59:35 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: a9f5c290465960eb X-CR-MTA-TID: 64aa7808 Received: from 0590521c32f2.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 9B0706FB-547E-406E-88EF-0484B21BD53A.1; Fri, 23 Dec 2022 14:59:27 +0000 Received: from EUR04-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 0590521c32f2.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 23 Dec 2022 14:59:27 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JD4hd+xL9LmpyUKtB6xffg5bgDaZ8xrfwvETON9FXJunNLs/T6gqzJDcnBXDfP735UwbClBhDKXLvBl9aXk8bSQhbaijDtZjPb2YVAKi4rkXJgySJ0V1cJ2QIPTsbob9umiPO7yEvcT8jtw53uJPiyPo7qw6rhQJjvcpqE12vXla1YzDHZwT9jkTgZul+/60YaI0G+XbRNw7L58ULogMkjXtxeSNZlBCvIXmG2/G911SWNZFueP7NWH3ZnRz+f/Ka3rAPIexSbDYce5A8t8SLlIf+kRwYazxrUeIQQA9Z1JD10f4k9l8BI2uNM0CIa+BRQjL3KYJFq5Z8TKRmbI6Jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=44Nqj/4bHgphtluox1yzY0GbKckVJnkBppp2LbMUctI=; b=FphlWOXx4q01WZxLlTO15p8Q+b0qpRHSCmVzBdPwClyHYLneF+L7gnEN5aZsKhfzfmq2oXOmcNNcs0V0b5Vd1wC3wOrtjTbdxhSdMxqVYXJMbxiZKmfJhluMuXh5jMJaVzLvK8JpdiCU9P3C3Ilwi647rwu9UXOuhROghRbe9kTWCvF8ZQ5vP09u+pxfQBaGGLCyCzh6Dw8BW9sNir8kk2YAbotiw1OBagnOwyvY8GcopAFVN+Hg/GU5IIrPY8ZSDAnWmHNRM1VHolzlHXcKihAoI2u95QOIohCmswdiDu2ApDIpBUmBidC6I6cM9ZdkCriEsE/JJ73LhacyArxVYQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=44Nqj/4bHgphtluox1yzY0GbKckVJnkBppp2LbMUctI=; b=t4y867m2xZcIYvHGW6JIC7X+C7J8dTVp5O964leHDRQm4XpbKW8LzT7HEiyOIHfUlL9FkyAO7gX5paMv7RaIE9VIsD9BffLkNIv23aYEB0HIcP3VLcFiJ/sVyzbK0NG8penusyiFNLkCDLgDRIkfNrItP3WEsz6eGW9z/SV3/z8= Received: from PAWPR08MB8982.eurprd08.prod.outlook.com (2603:10a6:102:33f::20) by DB9PR08MB8313.eurprd08.prod.outlook.com (2603:10a6:10:3df::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5944.11; Fri, 23 Dec 2022 14:59:20 +0000 Received: from PAWPR08MB8982.eurprd08.prod.outlook.com ([fe80::66e4:4940:d096:4f7]) by PAWPR08MB8982.eurprd08.prod.outlook.com ([fe80::66e4:4940:d096:4f7%9]) with mapi id 15.20.5944.006; Fri, 23 Dec 2022 14:59:20 +0000 From: Wilco Dijkstra To: "Alejandro Colomar (man-pages)" CC: 'GNU C Library' Subject: [PATCH 1/1] string: Add stpecpy(3) Thread-Topic: [PATCH 1/1] string: Add stpecpy(3) Thread-Index: AQHZFtT6/KFbdt6qiUqBEwzw0P1lag== Date: Fri, 23 Dec 2022 14:59:20 +0000 Message-ID: Accept-Language: en-GB, en-US Content-Language: en-GB X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; x-ms-traffictypediagnostic: PAWPR08MB8982:EE_|DB9PR08MB8313:EE_|AM7EUR03FT060:EE_|DU0PR08MB7764:EE_ X-MS-Office365-Filtering-Correlation-Id: 9c0c14b3-72ee-48f8-d5f9-08dae4f64e98 x-checkrecipientrouted: true nodisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: 7KM8U550DR3F7bG5GhbsJsXGaJ7aySd4S1EqlNf0sAmp5URZQi3nvOPvEsn6tR2wJS/iqSD/HhMg46qxsP3Tt7xK5do64hBi71aZJNIry7vpU7JVYzSnQ7DBLbiubUCmwumAizg/UUC85BBjTjlDCdmJcDWFDbeouruTobm57gYFDF1Q9bRcQygnsilXnI3AceARO+mplCHkVnD5WCfxoFkQALCwYXJN5fd6qSMr9RGICcp1b3bssfae0m8I3IvaDE/qHRd0bOWc2VgoGRdwRND4Kjk49kSZpw+Xo00Ar9LeFcuhEh/eaTlYMvCdzoc1i4SydBVVc7tPkuN88feBeqZxlG9vQxsQ+qtO+pwvgIn6X2XhDBOra5PiaGGxX1DjFvUa1tTUBUz2Nwa359H600z9i1/OqNJB4Gf+nQxJvrGRlwrXcNQfkuNrB07sFUhqFlAV0oARViNArZEGoqJWiJRHhKZtoZBPiT1UelFbEh/4rgBYvgl64qOq+jRau8EhiiN/zBdzhI7Ue0DCdfN0fdmWbNAflZ9ZEvVTgQpmJHZ9B5OiMk83SOkpTrN4hAByctQESi0mp6Oi11TN00rlL06X3Nqp78vDz2ATkuc+1R4+2vadw4LrTZUSjETLOLYSgVCtjG3T9YakKTMpMW1Mv2QUmG6KFw5NYamMwhxidT5fL1L7yAOKPlYIDYIusKWWeWTYXH7kead2GL/MRZ8XOg== X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAWPR08MB8982.eurprd08.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(396003)(366004)(376002)(39850400004)(136003)(346002)(451199015)(122000001)(38100700002)(83380400001)(86362001)(66446008)(33656002)(38070700005)(5660300002)(2906002)(66946007)(76116006)(66556008)(8676002)(4326008)(64756008)(66476007)(8936002)(55016003)(41300700001)(9686003)(26005)(186003)(6506007)(7696005)(6916009)(478600001)(316002)(91956017)(71200400001)(52536014);DIR:OUT;SFP:1101; Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR08MB8313 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM7EUR03FT060.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 672358f7-95c0-4fa6-5312-08dae4f6456a X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kRH+WVKqgAQWG++RGiKGFff2xQWtS1KOH7TKwKfX95quEPLRgiIAJHHRpfyqlg0aThAlc+LTZohxagnA8sI3jbfFhK2j7w/vUIl3rk3gGzRK9UwqSeU2dpc6keNOcFYLv7RAC5hKD0tfyg/jwtN4qVkECshHmEz93KwQAhvSth20FZjYSBv5n7lFtXGl4QsGQZ9qU6a9uYm1OAGs04atBbYgL9vuSnvRtxY/N95it3WMx0S4eQsY524FYyilMR2BVTAqW1UzvOfmsWNiRrwnIbFU9Nqp2qlw5xqhl8WuLvg0uZ+5pSD1d5yCnOlpMJBRux/xTRoS6nG77WdeS/aoN81NR9CMZw0+BITQDlAPIyuuLDwcdI5PYYz440b76DnIH4htTrc3xrlgW1r4so2RQjWGCaNdn9QG3JTq4gwbZU12WisMEpVku7vfxIwe8TpIxAfP/tJ0kR+ILUr62noOZvnoH+uQKcgET6fvxnt5JKpIMbB3LL8ptzbP8YcGV4tL0DePk1nZIeATQJcYooQzEF6ST4S2Wk3jHkAW+ZMc2MzgBfsAcZ5L+aHSVfIieIB94/Ql56Og9vukGurXAgRy4WPHwUggLDLQOXJbrrQllY1KeeH0E91JEp3Hs2TUvudYgJMHx449s9PlcalNVF7dXHlgzHjqqn2IgGARX2Bju7kSKGNVKcDDmZ+loHv71q0TpbEQ5qdWE5b42tomnDcvtg== X-Forefront-Antispam-Report: CIP:63.35.35.123;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:64aa7808-outbound-1.mta.getcheckrecipient.com;PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com;CAT:NONE;SFS:(13230022)(4636009)(39860400002)(346002)(396003)(136003)(376002)(451199015)(46966006)(40470700004)(36840700001)(36860700001)(81166007)(86362001)(70586007)(8936002)(52536014)(356005)(5660300002)(70206006)(33656002)(6862004)(26005)(2906002)(82310400005)(8676002)(40480700001)(4326008)(336012)(7696005)(6506007)(9686003)(83380400001)(478600001)(186003)(316002)(55016003)(40460700003)(47076005)(41300700001)(82740400003);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Dec 2022 14:59:35.7448 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9c0c14b3-72ee-48f8-d5f9-08dae4f64e98 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[63.35.35.123];Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: AM7EUR03FT060.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR08MB7764 X-Spam-Status: No, score=-5.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,FORGED_SPF_HELO,KAM_DMARC_NONE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE,TXREP,UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hi Alex,=0A= =0A= >> Given strlcpy and strlcat are in POSIX next and therefore bar=0A= >> some extraordinary event will be in glibc, I think we should=0A= >> probably wait until those two land, then see if there's still=0A= >> an appetite for stpecpy in glibc.=0A= >=0A= > I disagree for the following reasons.=0A= >=0A= > strlcpy(3)/strlcat(3) are designed to be _slow_, in exchange for added = =0A= > simplicity and safety. That's what Theo told me about them. They didn't= care =0A= > about performance. The two performance issues are:=0A= =0A= We'd need actual benchmarks to confirm there is a detectable performance=0A= difference in typical scenarios. So calling strlcpy slow is premature. Look= ing=0A= at the proposed stpecpy, it seems it has a lot more branches and special ca= ses=0A= compared to a typical strlcpy, and that adds extra overhead. Using memccpy= =0A= is risky too since that is often not optimized.=0A= =0A= > - Traverse the entire input string, to make sure it's a string. stpecpy= (3) =0A= > instead only reads what's necessary for the copy; it stops reading after = truncation.=0A= =0A= Almost all strings are short and few cases need truncation, so I don't see = the issue.=0A= People concerned about performance wouldn't use the standard string functio= ns=0A= anyway.=0A= =0A= > - strlcat(3) finds the terminating null byte; that's something you alrea= dy know =0A= > where it is, with functions that return a useful pointer (mempcpy(3), stp= cpy(3), =0A= > and stpecpy(3)).=0A= =0A= If you know the end of the destination string then don't use concatenation.= Easy!=0A= =0A= In fact compilers could inline the 'dest +=3D strlen (dest)' part of strcat= and call=0A= strcpy instead. This allows optimization of the strlen in case you know the= size=0A= of the destination string. This is true for strlcpy too, a compiler could j= ust inline=0A= it and optimize the strlen (src).=0A= =0A= > The reason that triggered me wanting to add this function is seeing strnc= py(3) =0A= > used for a patch to some glibc internals themselves. Using strlcpy(3)/ca= t(3) in =0A= > glibc internals would be bad for performance; I would hope that glibc use= s the =0A= > optimal internals, even if it also provides slow functions for users.=0A= =0A= Most internal uses are unlikely to be performance critical, and correctness= is kind=0A= of important for libraries.=0A= =0A= IMHO inventing many slightly different non-standard string functions is wha= t=0A= causes performance and correctness issues. People disagree about the semant= ics=0A= (strlcpy has been argued over for a decade or so). Even if a library suppor= ts them,=0A= you never know which implementations are actually well optimized (obviously= =0A= this varies between ISA and different libc's). So which non-standard string= function=0A= is safe to use across all targets and libraries?=0A= =0A= In contrast we can be pretty sure that the standard strlen, memcpy etc are = both=0A= correct and efficient on all targets/libc's.=0A= =0A= Cheers,=0A= Wilco=