From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dan Carpenter Subject: Re: [PATCH 2/3] string: provide strscpy() and strscpy_truncate() Date: Wed, 6 May 2015 18:01:40 +0300 Message-ID: <20150506150140.GB12986@mwanda> References: <1430409677-13284-1-git-send-email-cmetcalf@ezchip.com> <1430409677-13284-3-git-send-email-cmetcalf@ezchip.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Received: from userp1040.oracle.com ([156.151.31.81]:30659 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751147AbbEFPCw (ORCPT ); Wed, 6 May 2015 11:02:52 -0400 Content-Disposition: inline In-Reply-To: <1430409677-13284-3-git-send-email-cmetcalf@ezchip.com> Sender: linux-arch-owner@vger.kernel.org List-ID: To: Chris Metcalf Cc: Linus Torvalds , Al Viro , Fabian Frederick , Randy Dunlap , Rickard Strandqvist , gregkh@linuxfoundation.org, Peter Zijlstra , "David S. Miller" , Frederic Weisbecker , Andrew Morton , Sam Ravnborg , Stephen Rothwell , Theodore Ts'o , Grant Likely , Linux Kernel Mailing List , linux-arch@vger.kernel.org On Thu, Apr 30, 2015 at 12:01:16PM -0400, Chris Metcalf wrote: > +ssize_t strscpy(char *dest, const char *src, size_t count) > +{ > + ssize_t res = strscpy_truncate(dest, src, count); > + if (res < 0 && count != 0) > + dest[0] = '\0'; How is this better than returning a truncated string? Is it just because the caller was naughty so we give them a spanking? > + return res; > +} regards, dan carpenter