From nobody Wed Mar 27 11:26:21 2024 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4V4PWK4SMmz5FHt3; Wed, 27 Mar 2024 11:26:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4V4PWK2DD8z4cCW; Wed, 27 Mar 2024 11:26:21 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1711538781; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=3wpRbmCmVd+n62UooATlOfAUjBSurVcXl3/Ch/hYKvQ=; b=ZPOarVPV2QTo0Y9pjBjUUu0cIwL+JPsnr3y3djzSVXq2bXT/YM4qxYjt54CZKIWvm4dfs4 Bd6a3atfwU1jWZLZyAwpVUdjhAI+yweKXuji6cvID7WmrD/sqJzXbcYG9kc9rTCOdVit+l OHvBYiUOgQsrsAzZFvHRdDfttBt89l4uWqqzHfcSEFbDZb0BF8QURu2D4VQ14hEWpBHOI5 g9pp5PqkaVMJmdHoIMjLk+t0Wyj44fKUFAqOFDU3IcEkU1q/VeFNQRhDTUNgqohgkRG3LS NL3HtTxAZ9dvHrnIsSltq1Vkm5jRjHhfqMDMKVDbdBSr/xqSZ1U4BqxjOrUO0A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1711538781; a=rsa-sha256; cv=none; b=XqGR1DEp3M8ljj5vkCZCncvi1WQl9zFVHfCgGvoDflniFT2JKX6DbHT1DomeUBOUdDc8uO U3jkKa8LIc4OVITu9WBzHXyLTyYscGOlGJ2AnA0VdurGCf6AV8B7U50LJ0MKs0EgThy2P/ c/7MhJ1TaT9ZCbYC9KA0Q2VhiWNODWhzXB4lreeYJTTit9p29GeowNs6Dwjl6oAoNQ4bcS dTomLzQbfFhdjrkgi6YPLmyvy7lcZewUkbki4bR0HxmjJHvKZwvULNleMgpXUpY5nmFQxq 3Fm4ZevxxyxAZV1rlrDN4MSbNU8/MUu9SizlUFL1K+Vf9HAywo98We9S41m+9Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1711538781; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=3wpRbmCmVd+n62UooATlOfAUjBSurVcXl3/Ch/hYKvQ=; b=AQAzFq40cVrMFPSJrFD8Yu0+eSH7VxafWg/6jpYhYPB4s8rCSCgkLyWLVR1Vu8TkUbsECn 7sCxFfGYc5AKKyXSiooeRYOGcKaBHtr6mJJMfsXLq6Es9izpYBcH8ORoAp26KlmUAjrVlq mjMrOzihi2sy1UllcsQM7VaJLStulZ3LHW1uSYhohxU1CmHByfjcdAe6Gitd9ZUIDDreUE qKMWiZmEr4dEr8uC0sdRUPdsklTgPnDCafKVEWuVaWnJdFdqe3rrrkxhbxRPhmcTahs30v JJCbKPPHkXNxznUFkwxDO+rHdxeARjDlBLT80bJQGUshNuH6vrR6SjopUk+L2g== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4V4PWK1qQxzj2M; Wed, 27 Mar 2024 11:26:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 42RBQLtq003888; Wed, 27 Mar 2024 11:26:21 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 42RBQLNh003885; Wed, 27 Mar 2024 11:26:21 GMT (envelope-from git) Date: Wed, 27 Mar 2024 11:26:21 GMT Message-Id: <202403271126.42RBQLNh003885@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= Subject: git: 437d53daf71a - main - ln: Use stdbool, style nits. List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: des X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 437d53daf71a357aae960881ef037564736f7441 Auto-Submitted: auto-generated The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=437d53daf71a357aae960881ef037564736f7441 commit 437d53daf71a357aae960881ef037564736f7441 Author: Dag-Erling Smørgrav AuthorDate: 2024-03-27 10:03:49 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2024-03-27 10:03:49 +0000 ln: Use stdbool, style nits. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: imp, allanjude Differential Revision: https://reviews.freebsd.org/D44511 --- bin/ln/ln.c | 76 +++++++++++++++++++++++++++++++------------------------------ 1 file changed, 39 insertions(+), 37 deletions(-) diff --git a/bin/ln/ln.c b/bin/ln/ln.c index 2a4597b5fe36..31fe3b35e25e 100644 --- a/bin/ln/ln.c +++ b/bin/ln/ln.c @@ -37,24 +37,25 @@ #include #include #include +#include #include #include #include #include -static int fflag; /* Unlink existing files. */ -static int Fflag; /* Remove empty directories also. */ -static int hflag; /* Check new name for symlink first. */ -static int iflag; /* Interactive mode. */ -static int Pflag; /* Create hard links to symlinks. */ -static int sflag; /* Symbolic, not hard, link. */ -static int vflag; /* Verbose output. */ -static int wflag; /* Warn if symlink target does not +static bool fflag; /* Unlink existing files. */ +static bool Fflag; /* Remove empty directories also. */ +static bool hflag; /* Check new name for symlink first. */ +static bool iflag; /* Interactive mode. */ +static bool Pflag; /* Create hard links to symlinks. */ +static bool sflag; /* Symbolic, not hard, link. */ +static bool vflag; /* Verbose output. */ +static bool wflag; /* Warn if symlink target does not * exist, and -f is not enabled. */ static char linkch; -static int linkit(const char *, const char *, int); -static void usage(void); +static int linkit(const char *, const char *, bool); +static void usage(void) __dead2; int main(int argc, char *argv[]) @@ -79,41 +80,41 @@ main(int argc, char *argv[]) argv += optind; if (argc != 2) usage(); - exit(linkit(argv[0], argv[1], 0)); + exit(linkit(argv[0], argv[1], false)); } while ((ch = getopt(argc, argv, "FLPfhinsvw")) != -1) switch (ch) { case 'F': - Fflag = 1; + Fflag = true; break; case 'L': - Pflag = 0; + Pflag = false; break; case 'P': - Pflag = 1; + Pflag = true; break; case 'f': - fflag = 1; - iflag = 0; - wflag = 0; + fflag = true; + iflag = false; + wflag = false; break; case 'h': case 'n': - hflag = 1; + hflag = true; break; case 'i': - iflag = 1; - fflag = 0; + iflag = true; + fflag = false; break; case 's': - sflag = 1; + sflag = true; break; case 'v': - vflag = 1; + vflag = true; break; case 'w': - wflag = 1; + wflag = true; break; case '?': default: @@ -124,21 +125,21 @@ main(int argc, char *argv[]) argc -= optind; linkch = sflag ? '-' : '='; - if (sflag == 0) - Fflag = 0; - if (Fflag == 1 && iflag == 0) { - fflag = 1; - wflag = 0; /* Implied when fflag != 0 */ + if (!sflag) + Fflag = false; + if (Fflag && !iflag) { + fflag = true; + wflag = false; /* Implied when fflag is true */ } - switch(argc) { + switch (argc) { case 0: usage(); /* NOTREACHED */ case 1: /* ln source */ - exit(linkit(argv[0], ".", 1)); + exit(linkit(argv[0], ".", true)); case 2: /* ln source target */ - exit(linkit(argv[0], argv[1], 0)); + exit(linkit(argv[0], argv[1], false)); default: ; } @@ -157,7 +158,7 @@ main(int argc, char *argv[]) if (!S_ISDIR(sb.st_mode)) usage(); for (exitval = 0; *argv != targetdir; ++argv) - exitval |= linkit(*argv, targetdir, 1); + exitval |= linkit(*argv, targetdir, true); exit(exitval); } @@ -208,14 +209,15 @@ samedirent(const char *path1, const char *path2) } static int -linkit(const char *source, const char *target, int isdir) +linkit(const char *source, const char *target, bool isdir) { - struct stat sb; - const char *p; - int ch, exists, first; char path[PATH_MAX]; char wbuf[PATH_MAX]; char bbuf[PATH_MAX]; + struct stat sb; + const char *p; + int ch, first; + bool exists; if (!sflag) { /* If source doesn't exist, quit now. */ @@ -278,7 +280,7 @@ linkit(const char *source, const char *target, int isdir) /* * If the file exists, first check it is not the same directory entry. */ - exists = !lstat(target, &sb); + exists = lstat(target, &sb) == 0; if (exists) { if (!sflag && samedirent(source, target)) { warnx("%s and %s are the same directory entry",