Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966581AbcCPKxr (ORCPT ); Wed, 16 Mar 2016 06:53:47 -0400 Received: from lb2-smtp-cloud3.xs4all.net ([194.109.24.26]:58289 "EHLO lb2-smtp-cloud3.xs4all.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965768AbcCPKxo (ORCPT ); Wed, 16 Mar 2016 06:53:44 -0400 From: Paul Bolle To: Michal Marek Cc: Josh Boyer , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] kconfig: add chomp like helper function Date: Wed, 16 Mar 2016 11:53:38 +0100 Message-Id: <1458125619-28093-1-git-send-email-pebolle@tiscali.nl> X-Mailer: git-send-email 2.4.3 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 994 Lines: 44 Add a helper function that strips trailing new lines and carriage returns from strings. Call it chomp, after the perl function that inspired it. Signed-off-by: Paul Bolle --- scripts/kconfig/confdata.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index 0b7dc2fd7bac..51904c423411 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -248,6 +248,28 @@ e_out: return -1; } +/* + * Return newly allocated copy of string "in" with all trailing new lines and + * carriage returns removed. + */ +static char *chomp(char *in) +{ + size_t last = strlen(in); + char *copy; + + copy = malloc(last + 1); + if (!copy) + return NULL; + + strcpy(copy, in); + if (last) + last--; + while (last && (copy[last] == '\r' || copy[last] == '\n')) + copy[last--] = '\0'; + + return copy; +} + int conf_read_simple(const char *name, int def) { FILE *in = NULL; -- 2.4.3