From patchwork Tue Nov 1 08:01:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 9407047 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id AEC7360721 for ; Tue, 1 Nov 2016 08:02:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A03B7295E5 for ; Tue, 1 Nov 2016 08:02:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 937C2295F3; Tue, 1 Nov 2016 08:02:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8104D295E5 for ; Tue, 1 Nov 2016 08:02:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1167900AbcKAIC2 (ORCPT ); Tue, 1 Nov 2016 04:02:28 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:33020 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1167893AbcKAIC1 (ORCPT ); Tue, 1 Nov 2016 04:02:27 -0400 X-IronPort-AV: E=Sophos;i="5.20,367,1444665600"; d="scan'208";a="938912" Received: from unknown (HELO cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 01 Nov 2016 16:01:56 +0800 Received: from localhost.localdomain (unknown [10.167.226.34]) by cn.fujitsu.com (Postfix) with ESMTP id 7242341B4BC1; Tue, 1 Nov 2016 16:01:50 +0800 (CST) From: Qu Wenruo To: linux-btrfs@vger.kernel.org, dsterba@suse.cz Subject: [PATCH v3 1/4] btrfs-progs: utils: Introduce function to escape characters Date: Tue, 1 Nov 2016 16:01:43 +0800 Message-Id: <20161101080147.13163-2-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.10.1 In-Reply-To: <20161101080147.13163-1-quwenruo@cn.fujitsu.com> References: <20161101080147.13163-1-quwenruo@cn.fujitsu.com> MIME-Version: 1.0 X-yoursite-MailScanner-ID: 7242341B4BC1.AC98E X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: quwenruo@cn.fujitsu.com Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Introduce new function, escape_string_inplace(), to escape specified characters in place. Signed-off-by: Qu Wenruo --- utils.c | 17 +++++++++++++++++ utils.h | 2 ++ 2 files changed, 19 insertions(+) diff --git a/utils.c b/utils.c index 3f54245..69faae1 100644 --- a/utils.c +++ b/utils.c @@ -4251,3 +4251,20 @@ unsigned int rand_range(unsigned int upper) */ return (unsigned int)(jrand48(rand_seed) % upper); } + +void string_escape_inplace(char *restrict string, char *restrict escape_chars) +{ + int i, j; + + for (i = 0; i < strlen(escape_chars); i++) { + j = 0; + while (j < strlen(string)) { + if (string[j] == escape_chars[i]) { + memmove(string + j, string + j + 1, + strlen(string) -j); + continue; + } + j++; + } + } +} diff --git a/utils.h b/utils.h index 1a2dbcd..b36d411 100644 --- a/utils.h +++ b/utils.h @@ -457,4 +457,6 @@ unsigned int rand_range(unsigned int upper); /* Also allow setting the seed manually */ void init_rand_seed(u64 seed); +void string_escape_inplace(char *restrict string, char *restrict escape_chars); + #endif