From patchwork Mon May 24 11:23:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 446446 Delivered-To: patch@linaro.org Received: by 2002:a02:7a1b:0:0:0:0:0 with SMTP id a27csp3253790jac; Mon, 24 May 2021 04:23:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxloDHbFW4YTfnOQna6o/wzvx3iNs0zApDLCMMKEUUDrRHAfFohIZKFUDDsufx2J/zwUQcC X-Received: by 2002:a67:65c5:: with SMTP id z188mr21214964vsb.22.1621855428385; Mon, 24 May 2021 04:23:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621855428; cv=none; d=google.com; s=arc-20160816; b=tohc098q91U6Hi4qvZfJneP7+VfBzHGqP81MZ4uxU+QHNKzGgOmlJQdVZjg0l8SoAM NEt/a3rM2H/vmI73S1f2bwiqZLu5YZdArMGYzwY8hI1KokfQEJlvt9NLN9oxUvFe8p9w cH8zSwenjTvv7lnmQXO4sSgVWsjiAccakakaWAXMHm7ilb/QnA0D9KmkLwaZQqw1Kphw 6eJbKGbp43AYG2++F7xEe4D+2sV3aWhtz0QW7JoADZXH1DXXitwfhU4LgUiHb3lBSss4 ld4FxkErbpTUjRr2JiiOuiXGzbs2HC9bHjetAn4FslwnMh8dB+C8+uZ+fN/1M3jbYgI2 Xxlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:to:from:dkim-signature; bh=N8cOTqyCKuHxxXbbqblShpEqwML2XUs9Ugh7l6qxcUA=; b=bclTfH4ZhVWqKAgSQBSd/obCSaZitkbrWQKLbvefXuBcmV7cdSPNzMg19rCXmSncr/ f5ZbGzep8IKvPTxOF89TWNAsLQ0/Bb7kVJmIzR3CxUG+hZQQK/4EDzx/vbVx5xce6uoI BWsDa8woSdXgwXc1aUu3nqGLtAMZ/YC3nmWDORgLEbhkw0rE8lO4kazaDfmw3k7u6B// p7GuUC9I6xr9Sn6T03sb9uUtwBskATgwYeTaowuuCoCj/lmT2Ra/3tq9ru9cFTfKS5dg K7XoXgkclSIGwnz9MJwNkm3jks24Vj1yyho7CcQuTB5U8pfbHmhXVli3jDJBcueHxYkx W3/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=V1Yo2kiA; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id s13si5147699uap.152.2021.05.24.04.23.48 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 24 May 2021 04:23:48 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=V1Yo2kiA; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:58628 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ll8gV-0005Yw-SP for patch@linaro.org; Mon, 24 May 2021 07:23:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58440) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ll8gM-0005YT-34 for qemu-devel@nongnu.org; Mon, 24 May 2021 07:23:38 -0400 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]:50915) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ll8gK-0004lK-1W for qemu-devel@nongnu.org; Mon, 24 May 2021 07:23:37 -0400 Received: by mail-wm1-x32f.google.com with SMTP id t206so14732636wmf.0 for ; Mon, 24 May 2021 04:23:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=N8cOTqyCKuHxxXbbqblShpEqwML2XUs9Ugh7l6qxcUA=; b=V1Yo2kiAD7iuoFPVUfNv7eXDzsXcSK2N2tohXehhlH321CV0IAdlV731oeKO/7tuVt pGpVev7MTRRXoKvtwbRrz5KuW9Eelacq8XwxTeUZXS3hrPRu750QlR2c7c169Wo0ex3k LGGMVKvhqWNVT2Te1oAAKmsD9LYXEJun3QqYZrO1chJZLoKwEuVIXZBOSREBAYBiQKLy jyc34MZl5/lkBBBRu1odHqPmRwJ5Rfr9wqpcouoxjSxWHGiDM6hKfh7LvegjHzQLzVCD VKmqHRN9DAIiaOCB6g4bkBkKOCK0FYxt6fuDuJyQ0o6KJoGMWpBYBT9iD3DnQSrTaiDv PtQg== 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:mime-version :content-transfer-encoding; bh=N8cOTqyCKuHxxXbbqblShpEqwML2XUs9Ugh7l6qxcUA=; b=KizmcoGZ2ntXAskPCq6NYuS0CF24xx39EHqSd+GtZ31s/nWiU6D8c6WAqsWMlzX/0H jb0OZayzQQvRWtsgGyxmoaBHkk724YrWPLmhL3Nalq3Ps2AgUZNnmZxGKiduRU/KOGsy Ko9jKyy9q4Ks+CLO9yfTlqABUknKFiqjXv1NNJ1ub3YPWHmoCID1+PjJGqKLkQEnm+N0 VDBRyZook/BwjXhha6T3vJC0jpvltgRqGhZ1Ldbml1fz2jwMIe/mAsgEm33eK5ljLdKX pvsfcmXjC+Wi2cqPEuqvkMNVyDe2dh/RcMw6nCC3RlX3gCOv3x2VzSgFFl9Eoh7kfNsp jrYw== X-Gm-Message-State: AOAM533wUKXfXra2eeJWE1gLXe4/FZBIUriNUX05gKPL6yhMGb7Nel/u oBcsWBYQkHyVMPKDKIEwl01lCw== X-Received: by 2002:a7b:c778:: with SMTP id x24mr19304208wmk.23.1621855413981; Mon, 24 May 2021 04:23:33 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id d14sm5370598wra.5.2021.05.24.04.23.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 May 2021 04:23:33 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 4CFD31FF7E; Mon, 24 May 2021 12:23:32 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [RFC PATCH] linux-user: glib-ify is_proc_myself Date: Mon, 24 May 2021 12:23:23 +0100 Message-Id: <20210524112323.2310-1-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32f; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Laurent Vivier , yamamoto@midokura.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" I'm not sure if this is neater than the original code but it does remove a bunch of the !strcmp's in favour of glib's more natural bool results. While we are at it make the function a bool return and fixup the fake_open function prototypes. Signed-off-by: Alex Bennée --- linux-user/syscall.c | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) -- 2.20.1 diff --git a/linux-user/syscall.c b/linux-user/syscall.c index e739921e86..18e953de9d 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -7987,33 +7987,27 @@ static int open_self_auxv(void *cpu_env, int fd) return 0; } -static int is_proc_myself(const char *filename, const char *entry) +static bool is_proc_myself(const char *filename, const char *entry) { - if (!strncmp(filename, "/proc/", strlen("/proc/"))) { + if (g_str_has_prefix(filename, "/proc/")) { filename += strlen("/proc/"); - if (!strncmp(filename, "self/", strlen("self/"))) { + if (g_str_has_prefix(filename, "self/")) { filename += strlen("self/"); - } else if (*filename >= '1' && *filename <= '9') { - char myself[80]; - snprintf(myself, sizeof(myself), "%d/", getpid()); - if (!strncmp(filename, myself, strlen(myself))) { - filename += strlen(myself); - } else { - return 0; + } else if (g_ascii_isdigit(*filename)) { + g_autofree char * myself = g_strdup_printf("%d/", getpid()); + if (!g_str_has_prefix(filename, myself)) { + return false; } - } else { - return 0; - } - if (!strcmp(filename, entry)) { - return 1; + filename += strlen(myself); } + return g_str_has_prefix(filename, entry); } - return 0; + return false; } #if defined(HOST_WORDS_BIGENDIAN) != defined(TARGET_WORDS_BIGENDIAN) || \ defined(TARGET_SPARC) || defined(TARGET_M68K) || defined(TARGET_HPPA) -static int is_proc(const char *filename, const char *entry) +static bool is_proc(const char *filename, const char *entry) { return strcmp(filename, entry) == 0; } @@ -8097,7 +8091,7 @@ static int do_openat(void *cpu_env, int dirfd, const char *pathname, int flags, struct fake_open { const char *filename; int (*fill)(void *cpu_env, int fd); - int (*cmp)(const char *s1, const char *s2); + bool (*cmp)(const char *s1, const char *s2); }; const struct fake_open *fake_open; static const struct fake_open fakes[] = {