From nobody Sun Apr 28 04:09:57 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1621855494; cv=none; d=zohomail.com; s=zohoarc; b=C7P4H7fXg88GIoDaWEgzJN5s7TpuXKQN9CfiCp8MPFUISAstUu8z1NkmCdLRsdkzV58hhmLjkY3FtrefvGgpGAWObe/k+xdvG46VpNuM7Fz1N8Wl2yUdyCTQSiSwtJKi4hHJ63Qo9b5VaZHFrnHO40lJjA9YmPjo3HHtrGnChso= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621855494; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=N8cOTqyCKuHxxXbbqblShpEqwML2XUs9Ugh7l6qxcUA=; b=NE8yWnv/Ae9KUmTxUIjVMuDbP/nCVfCeE5qQoD6DEFS9s4W5/sfrQd5mNEy77FSwvgyCxciMpSUlp1deDl1XFimnKMDEfOicmKDRkT/Jf+4+d+9SEnczSmv9Ol3qd/4kN9/NBIZQv+Wa9b2zFgc17TeAlyAw56qDUvEBGVOp47g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1621855494778189.85034282346408; Mon, 24 May 2021 04:24:54 -0700 (PDT) Received: from localhost ([::1]:59630 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ll8hZ-0006G5-Ng for importer2@patchew.org; Mon, 24 May 2021 07:24:53 -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) 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) 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-Google-Smtp-Source: ABdhPJw8qHLme01Bx7hJOm67b7GRQ4xOAp32MaKyEQ1/gDLQVra5ZV4YeeBz2nEQl9W83RIz80TnYw== X-Received: by 2002:a7b:c778:: with SMTP id x24mr19304208wmk.23.1621855413981; Mon, 24 May 2021 04:23:33 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; 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=20Benn=C3=A9e?= , Laurent Vivier , yamamoto@midokura.com Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) 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=C3=A9e --- linux-user/syscall.c | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) 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; } =20 -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 +=3D strlen("/proc/"); - if (!strncmp(filename, "self/", strlen("self/"))) { + if (g_str_has_prefix(filename, "self/")) { filename +=3D strlen("self/"); - } else if (*filename >=3D '1' && *filename <=3D '9') { - char myself[80]; - snprintf(myself, sizeof(myself), "%d/", getpid()); - if (!strncmp(filename, myself, strlen(myself))) { - filename +=3D strlen(myself); - } else { - return 0; + } else if (g_ascii_isdigit(*filename)) { + g_autofree char * myself =3D g_strdup_printf("%d/", getpid()); + if (!g_str_has_prefix(filename, myself)) { + return false; } - } else { - return 0; - } - if (!strcmp(filename, entry)) { - return 1; + filename +=3D strlen(myself); } + return g_str_has_prefix(filename, entry); } - return 0; + return false; } =20 #if defined(HOST_WORDS_BIGENDIAN) !=3D 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) =3D=3D 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[] =3D { --=20 2.20.1