Re: CVS commit: src/usr.bin/stat

2024-03-14 Thread Roland Illig
Am 14.03.2024 um 21:27 schrieb Robert Elz:
> Date:Thu, 14 Mar 2024 20:53:13 +0100
> From:Roland Illig 
> Message-ID:  <9c7513f7-97b5-4d3b-9d66-dce483af7...@gmx.de>
>
>   | I don't think the flags '+' and '0' make sense for strings, that's why I
>   | decided to preserve existing behavior.
>
> But the change only affected things when the # flag was given.   I agree
> that + and 0 are meaningless for strings, but - isn't, and %-S would work,
> I see no reason why %#-S shouldn't work as well.
>
> Not exactly a serius problem, as clearly no-one ever seems to have
> been bothered by it, but no-one intentionally writes the code as it
> was (generating clear everything) - the ! was obviously just a thinko
> for ~.

I agree. Thank you for fixing the left-aligned output, I wrote a few
tests for these cases.

Roland



Re: CVS commit: src/usr.bin/stat

2024-03-14 Thread Robert Elz
Date:Thu, 14 Mar 2024 20:53:13 +0100
From:Roland Illig 
Message-ID:  <9c7513f7-97b5-4d3b-9d66-dce483af7...@gmx.de>

  | I don't think the flags '+' and '0' make sense for strings, that's why I
  | decided to preserve existing behavior.

But the change only affected things when the # flag was given.   I agree
that + and 0 are meaningless for strings, but - isn't, and %-S would work,
I see no reason why %#-S shouldn't work as well.

Not exactly a serius problem, as clearly no-one ever seems to have
been bothered by it, but no-one intentionally writes the code as it
was (generating clear everything) - the ! was obviously just a thinko
for ~.

kre


Re: CVS commit: src/usr.bin/stat

2024-03-14 Thread Roland Illig
Am 14.03.2024 um 20:38 schrieb Robert Elz:
> Module Name:  src
> Committed By: kre
> Date: Thu Mar 14 19:38:56 UTC 2024
>
> Modified Files:
>   src/usr.bin/stat: stat.c
>
> Log Message:
> While the change in 1.51 certainly retained binary compat with
> what was in 1.50 (while silencing LINT) - it was clearly not the
> correct change to make.   The code used !FLAG_POUND where it
> clearly meant ~FLAG_POUND ... the former is 0, so &= 0 could
> be replaced by =0 changing nothing.   But that's not what it
> should have been doing, other flags should not have been
> removed here, just FLAG_POUND.

I don't think the flags '+' and '0' make sense for strings, that's why I
decided to preserve existing behavior.

Roland



CVS commit: src/usr.bin/stat

2024-03-14 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Thu Mar 14 19:38:56 UTC 2024

Modified Files:
src/usr.bin/stat: stat.c

Log Message:
While the change in 1.51 certainly retained binary compat with
what was in 1.50 (while silencing LINT) - it was clearly not the
correct change to make.   The code used !FLAG_POUND where it
clearly meant ~FLAG_POUND ... the former is 0, so &= 0 could
be replaced by =0 changing nothing.   But that's not what it
should have been doing, other flags should not have been
removed here, just FLAG_POUND.

This problem seems to have existed since support for %#s
was first added in 2011, which kind of suggests how rarely
that format, particularly with other flags (like %#-s)
has ever been used (with no other flags, the bug would not
be noticed).


To generate a diff of this commit:
cvs rdiff -u -r1.51 -r1.52 src/usr.bin/stat/stat.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/stat/stat.c
diff -u src/usr.bin/stat/stat.c:1.51 src/usr.bin/stat/stat.c:1.52
--- src/usr.bin/stat/stat.c:1.51	Thu Mar 14 00:07:20 2024
+++ src/usr.bin/stat/stat.c	Thu Mar 14 19:38:56 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: stat.c,v 1.51 2024/03/14 00:07:20 rillig Exp $ */
+/*	$NetBSD: stat.c,v 1.52 2024/03/14 19:38:56 kre Exp $ */
 
 /*
  * Copyright (c) 2002-2011 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 #include 
 #if !defined(lint)
-__RCSID("$NetBSD: stat.c,v 1.51 2024/03/14 00:07:20 rillig Exp $");
+__RCSID("$NetBSD: stat.c,v 1.52 2024/03/14 19:38:56 kre Exp $");
 #endif
 
 #if ! HAVE_NBTOOL_CONFIG_H
@@ -1077,7 +1077,7 @@ format1(const struct stat *st,
 	 * First prefixlen chars are not encoded.
 	 */
 	if ((flags & FLAG_POUND) != 0 && ofmt == FMTF_STRING) {
-		flags = 0;
+		flags &= ~FLAG_POUND;
 		strncpy(visbuf, sdata, prefixlen);
 		/* Avoid GCC warnings. */
 		visbuf[prefixlen] = 0;



CVS commit: src/usr.bin/stat

2024-03-14 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Thu Mar 14 19:38:56 UTC 2024

Modified Files:
src/usr.bin/stat: stat.c

Log Message:
While the change in 1.51 certainly retained binary compat with
what was in 1.50 (while silencing LINT) - it was clearly not the
correct change to make.   The code used !FLAG_POUND where it
clearly meant ~FLAG_POUND ... the former is 0, so &= 0 could
be replaced by =0 changing nothing.   But that's not what it
should have been doing, other flags should not have been
removed here, just FLAG_POUND.

This problem seems to have existed since support for %#s
was first added in 2011, which kind of suggests how rarely
that format, particularly with other flags (like %#-s)
has ever been used (with no other flags, the bug would not
be noticed).


To generate a diff of this commit:
cvs rdiff -u -r1.51 -r1.52 src/usr.bin/stat/stat.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/stat

2024-03-13 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Mar 14 00:07:20 UTC 2024

Modified Files:
src/usr.bin/stat: stat.c

Log Message:
stat: fix lint warning about constant argument to '!'

No binary change.


To generate a diff of this commit:
cvs rdiff -u -r1.50 -r1.51 src/usr.bin/stat/stat.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/stat/stat.c
diff -u src/usr.bin/stat/stat.c:1.50 src/usr.bin/stat/stat.c:1.51
--- src/usr.bin/stat/stat.c:1.50	Mon Jan 29 22:01:58 2024
+++ src/usr.bin/stat/stat.c	Thu Mar 14 00:07:20 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: stat.c,v 1.50 2024/01/29 22:01:58 christos Exp $ */
+/*	$NetBSD: stat.c,v 1.51 2024/03/14 00:07:20 rillig Exp $ */
 
 /*
  * Copyright (c) 2002-2011 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 #include 
 #if !defined(lint)
-__RCSID("$NetBSD: stat.c,v 1.50 2024/01/29 22:01:58 christos Exp $");
+__RCSID("$NetBSD: stat.c,v 1.51 2024/03/14 00:07:20 rillig Exp $");
 #endif
 
 #if ! HAVE_NBTOOL_CONFIG_H
@@ -1077,7 +1077,7 @@ format1(const struct stat *st,
 	 * First prefixlen chars are not encoded.
 	 */
 	if ((flags & FLAG_POUND) != 0 && ofmt == FMTF_STRING) {
-		flags &= !FLAG_POUND;
+		flags = 0;
 		strncpy(visbuf, sdata, prefixlen);
 		/* Avoid GCC warnings. */
 		visbuf[prefixlen] = 0;



CVS commit: src/usr.bin/stat

2024-03-13 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Mar 14 00:07:20 UTC 2024

Modified Files:
src/usr.bin/stat: stat.c

Log Message:
stat: fix lint warning about constant argument to '!'

No binary change.


To generate a diff of this commit:
cvs rdiff -u -r1.50 -r1.51 src/usr.bin/stat/stat.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/stat

2024-01-29 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Jan 29 22:01:58 UTC 2024

Modified Files:
src/usr.bin/stat: Makefile stat.c

Log Message:
fix tools build


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/usr.bin/stat/Makefile
cvs rdiff -u -r1.49 -r1.50 src/usr.bin/stat/stat.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/stat/Makefile
diff -u src/usr.bin/stat/Makefile:1.14 src/usr.bin/stat/Makefile:1.15
--- src/usr.bin/stat/Makefile:1.14	Mon Jan 29 16:55:24 2024
+++ src/usr.bin/stat/Makefile	Mon Jan 29 17:01:58 2024
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.14 2024/01/29 21:55:24 christos Exp $
+#	$NetBSD: Makefile,v 1.15 2024/01/29 22:01:58 christos Exp $
 
 PROG=	stat
 
@@ -14,7 +14,9 @@ COPTS.stat.c+=	${CC_WNO_IMPLICIT_FALLTHR
 
 COPTS.stat.c += -Wno-format-nonliteral
 
+.if !defined(HOSTPROG)
 LDADD+=	-lutil
 DPADD+=	${LIBUTIL}
+.endif
 
 .include 

Index: src/usr.bin/stat/stat.c
diff -u src/usr.bin/stat/stat.c:1.49 src/usr.bin/stat/stat.c:1.50
--- src/usr.bin/stat/stat.c:1.49	Mon Jan 29 16:55:24 2024
+++ src/usr.bin/stat/stat.c	Mon Jan 29 17:01:58 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: stat.c,v 1.49 2024/01/29 21:55:24 christos Exp $ */
+/*	$NetBSD: stat.c,v 1.50 2024/01/29 22:01:58 christos Exp $ */
 
 /*
  * Copyright (c) 2002-2011 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 #include 
 #if !defined(lint)
-__RCSID("$NetBSD: stat.c,v 1.49 2024/01/29 21:55:24 christos Exp $");
+__RCSID("$NetBSD: stat.c,v 1.50 2024/01/29 22:01:58 christos Exp $");
 #endif
 
 #if ! HAVE_NBTOOL_CONFIG_H
@@ -63,7 +63,7 @@ __RCSID("$NetBSD: stat.c,v 1.49 2024/01/
 #include 
 #include 
 #include 
-#if HAVE_STRUCT_STAT_ST_FLAGS
+#if HAVE_STRUCT_STAT_ST_FLAGS && !HAVE_NBTOOL_CONFIG_H
 #include 
 #endif
 #include 
@@ -870,9 +870,11 @@ format1(const struct stat *st,
 	case SHOW_st_flags:
 		small = (sizeof(st->st_flags) == 4);
 		data = st->st_flags;
+		formats = FMTF_DECIMAL | FMTF_OCTAL | FMTF_UNSIGNED | FMTF_HEX;
+#if !HAVE_NBTOOL_CONFIG_H
 		sdata = flags_to_string((u_long)st->st_flags, "-");
-		formats = FMTF_DECIMAL | FMTF_OCTAL | FMTF_UNSIGNED | FMTF_HEX |
-		FMTF_STRING;
+		formats |= FMT_STRING;
+#endif
 		if (ofmt == 0)
 			ofmt = FMTF_UNSIGNED;
 		break;



CVS commit: src/usr.bin/stat

2024-01-29 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Jan 29 22:01:58 UTC 2024

Modified Files:
src/usr.bin/stat: Makefile stat.c

Log Message:
fix tools build


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/usr.bin/stat/Makefile
cvs rdiff -u -r1.49 -r1.50 src/usr.bin/stat/stat.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/stat

2024-01-29 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Jan 29 21:55:24 UTC 2024

Modified Files:
src/usr.bin/stat: Makefile stat.1 stat.c

Log Message:
PR/57891: Ricardo Branco: add symbolic flags printing (from FreeBSD)


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/usr.bin/stat/Makefile
cvs rdiff -u -r1.46 -r1.47 src/usr.bin/stat/stat.1
cvs rdiff -u -r1.48 -r1.49 src/usr.bin/stat/stat.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/stat/Makefile
diff -u src/usr.bin/stat/Makefile:1.13 src/usr.bin/stat/Makefile:1.14
--- src/usr.bin/stat/Makefile:1.13	Sat Jun  3 17:30:24 2023
+++ src/usr.bin/stat/Makefile	Mon Jan 29 16:55:24 2024
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.13 2023/06/03 21:30:24 lukem Exp $
+#	$NetBSD: Makefile,v 1.14 2024/01/29 21:55:24 christos Exp $
 
 PROG=	stat
 
@@ -14,4 +14,7 @@ COPTS.stat.c+=	${CC_WNO_IMPLICIT_FALLTHR
 
 COPTS.stat.c += -Wno-format-nonliteral
 
+LDADD+=	-lutil
+DPADD+=	${LIBUTIL}
+
 .include 

Index: src/usr.bin/stat/stat.1
diff -u src/usr.bin/stat/stat.1:1.46 src/usr.bin/stat/stat.1:1.47
--- src/usr.bin/stat/stat.1:1.46	Fri Jun 24 09:11:44 2022
+++ src/usr.bin/stat/stat.1	Mon Jan 29 16:55:24 2024
@@ -1,4 +1,4 @@
-.\"	$NetBSD: stat.1,v 1.46 2022/06/24 13:11:44 kre Exp $
+.\"	$NetBSD: stat.1,v 1.47 2024/01/29 21:55:24 christos Exp $
 .\"
 .\" Copyright (c) 2002-2011 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -27,7 +27,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd June 22, 2022
+.Dd January 29, 2023
 .Dt STAT 1
 .Os
 .Sh NAME
@@ -315,6 +315,11 @@ format with the extension that
 prints nanoseconds if available.
 .It Cm d , r
 Display actual device name.
+.It Cm f
+Display the flags of
+.Ar file
+as in
+.Nm ls Fl ldo .
 .It Cm g , u
 Display group or user name.
 .It Cm p

Index: src/usr.bin/stat/stat.c
diff -u src/usr.bin/stat/stat.c:1.48 src/usr.bin/stat/stat.c:1.49
--- src/usr.bin/stat/stat.c:1.48	Wed Jun 22 14:20:30 2022
+++ src/usr.bin/stat/stat.c	Mon Jan 29 16:55:24 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: stat.c,v 1.48 2022/06/22 18:20:30 kre Exp $ */
+/*	$NetBSD: stat.c,v 1.49 2024/01/29 21:55:24 christos Exp $ */
 
 /*
  * Copyright (c) 2002-2011 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 #include 
 #if !defined(lint)
-__RCSID("$NetBSD: stat.c,v 1.48 2022/06/22 18:20:30 kre Exp $");
+__RCSID("$NetBSD: stat.c,v 1.49 2024/01/29 21:55:24 christos Exp $");
 #endif
 
 #if ! HAVE_NBTOOL_CONFIG_H
@@ -63,6 +63,9 @@ __RCSID("$NetBSD: stat.c,v 1.48 2022/06/
 #include 
 #include 
 #include 
+#if HAVE_STRUCT_STAT_ST_FLAGS
+#include 
+#endif
 #include 
 
 #if HAVE_STRUCT_STAT_ST_FLAGS
@@ -867,8 +870,9 @@ format1(const struct stat *st,
 	case SHOW_st_flags:
 		small = (sizeof(st->st_flags) == 4);
 		data = st->st_flags;
-		sdata = NULL;
-		formats = FMTF_DECIMAL | FMTF_OCTAL | FMTF_UNSIGNED | FMTF_HEX;
+		sdata = flags_to_string((u_long)st->st_flags, "-");
+		formats = FMTF_DECIMAL | FMTF_OCTAL | FMTF_UNSIGNED | FMTF_HEX |
+		FMTF_STRING;
 		if (ofmt == 0)
 			ofmt = FMTF_UNSIGNED;
 		break;



CVS commit: src/usr.bin/stat

2024-01-29 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Jan 29 21:55:24 UTC 2024

Modified Files:
src/usr.bin/stat: Makefile stat.1 stat.c

Log Message:
PR/57891: Ricardo Branco: add symbolic flags printing (from FreeBSD)


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/usr.bin/stat/Makefile
cvs rdiff -u -r1.46 -r1.47 src/usr.bin/stat/stat.1
cvs rdiff -u -r1.48 -r1.49 src/usr.bin/stat/stat.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/stat

2022-07-21 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Thu Jul 21 10:08:28 UTC 2022

Modified Files:
src/usr.bin/stat: readlink.1

Log Message:
readlink: sort SEE ALSO


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/stat/readlink.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/stat/readlink.1
diff -u src/usr.bin/stat/readlink.1:1.5 src/usr.bin/stat/readlink.1:1.6
--- src/usr.bin/stat/readlink.1:1.5	Thu Jul 21 10:00:31 2022
+++ src/usr.bin/stat/readlink.1	Thu Jul 21 10:08:28 2022
@@ -1,4 +1,4 @@
-.\"	$NetBSD: readlink.1,v 1.5 2022/07/21 10:00:31 kre Exp $
+.\"	$NetBSD: readlink.1,v 1.6 2022/07/21 10:08:28 wiz Exp $
 .\"
 .\" Copyright (c) 2002-2011 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -92,8 +92,8 @@ and
 .Fl s .
 .El
 .Sh SEE ALSO
-.Xr stat 1 ,
 .Xr realpath 1 ,
+.Xr stat 1 ,
 .Xr lstat 2 ,
 .Xr readlink 2
 .Sh HISTORY



CVS commit: src/usr.bin/stat

2022-07-21 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Thu Jul 21 10:08:28 UTC 2022

Modified Files:
src/usr.bin/stat: readlink.1

Log Message:
readlink: sort SEE ALSO


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/stat/readlink.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/stat

2022-07-21 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Thu Jul 21 10:00:31 UTC 2022

Modified Files:
src/usr.bin/stat: readlink.1

Log Message:
Add an Xr to realpath(1) (which does much the same as readlink -f).
Try not to forget the damn comma!


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/stat/readlink.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/stat/readlink.1
diff -u src/usr.bin/stat/readlink.1:1.4 src/usr.bin/stat/readlink.1:1.5
--- src/usr.bin/stat/readlink.1:1.4	Wed Jun 22 22:25:08 2022
+++ src/usr.bin/stat/readlink.1	Thu Jul 21 10:00:31 2022
@@ -1,4 +1,4 @@
-.\"	$NetBSD: readlink.1,v 1.4 2022/06/22 22:25:08 wiz Exp $
+.\"	$NetBSD: readlink.1,v 1.5 2022/07/21 10:00:31 kre Exp $
 .\"
 .\" Copyright (c) 2002-2011 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -93,6 +93,7 @@ and
 .El
 .Sh SEE ALSO
 .Xr stat 1 ,
+.Xr realpath 1 ,
 .Xr lstat 2 ,
 .Xr readlink 2
 .Sh HISTORY



CVS commit: src/usr.bin/stat

2022-07-21 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Thu Jul 21 10:00:31 UTC 2022

Modified Files:
src/usr.bin/stat: readlink.1

Log Message:
Add an Xr to realpath(1) (which does much the same as readlink -f).
Try not to forget the damn comma!


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/stat/readlink.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/stat

2022-06-24 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Fri Jun 24 13:11:45 UTC 2022

Modified Files:
src/usr.bin/stat: stat.1

Log Message:
Remove the notge (I added a day or so ago) about IFS interfering with -s
output (potentially) - it is almost certainly wrong.


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 src/usr.bin/stat/stat.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/stat/stat.1
diff -u src/usr.bin/stat/stat.1:1.45 src/usr.bin/stat/stat.1:1.46
--- src/usr.bin/stat/stat.1:1.45	Thu Jun 23 23:41:26 2022
+++ src/usr.bin/stat/stat.1	Fri Jun 24 13:11:44 2022
@@ -1,4 +1,4 @@
-.\"	$NetBSD: stat.1,v 1.45 2022/06/23 23:41:26 uwe Exp $
+.\"	$NetBSD: stat.1,v 1.46 2022/06/24 13:11:44 kre Exp $
 .\"
 .\" Copyright (c) 2002-2011 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -195,9 +195,7 @@ option.
 Note that if you use a
 .Ar timefmt
 that contains embedded whitespace or shell
-meta-characters, or if the shell's
-.Dv IFS
-is set to a non-standard value,
+meta-characters,
 you will need to
 include appropriate quoting in the
 .Fl t



CVS commit: src/usr.bin/stat

2022-06-24 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Fri Jun 24 13:11:45 UTC 2022

Modified Files:
src/usr.bin/stat: stat.1

Log Message:
Remove the notge (I added a day or so ago) about IFS interfering with -s
output (potentially) - it is almost certainly wrong.


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 src/usr.bin/stat/stat.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/stat

2022-06-23 Thread Valeriy E. Ushakov
Module Name:src
Committed By:   uwe
Date:   Thu Jun 23 23:41:26 UTC 2022

Modified Files:
src/usr.bin/stat: stat.1

Log Message:
stat(1): Fix two more -width.


To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 src/usr.bin/stat/stat.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/stat/stat.1
diff -u src/usr.bin/stat/stat.1:1.44 src/usr.bin/stat/stat.1:1.45
--- src/usr.bin/stat/stat.1:1.44	Wed Jun 22 22:41:13 2022
+++ src/usr.bin/stat/stat.1	Thu Jun 23 23:41:26 2022
@@ -1,4 +1,4 @@
-.\"	$NetBSD: stat.1,v 1.44 2022/06/22 22:41:13 uwe Exp $
+.\"	$NetBSD: stat.1,v 1.45 2022/06/23 23:41:26 uwe Exp $
 .\"
 .\" Copyright (c) 2002-2011 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -429,7 +429,7 @@ File size, rounded to the nearest kiloby
 .It Ar datum
 A required field specifier, ending the conversion specification,
 being one of the following:
-.Bl -tag -width 11n
+.Bl -tag -width Cm
 .It Cm d
 Device upon which
 .Ar file
@@ -485,7 +485,7 @@ The following five field specifiers are 
 data in
 .Vt struct stat ,
 but are:
-.Bl -tag -width Ds
+.Bl -tag -width Cm
 .It Cm N
 The name of the file.
 .It Cm R



CVS commit: src/usr.bin/stat

2022-06-23 Thread Valeriy E. Ushakov
Module Name:src
Committed By:   uwe
Date:   Thu Jun 23 23:41:26 UTC 2022

Modified Files:
src/usr.bin/stat: stat.1

Log Message:
stat(1): Fix two more -width.


To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 src/usr.bin/stat/stat.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/stat

2022-06-22 Thread Valeriy E. Ushakov
Module Name:src
Committed By:   uwe
Date:   Wed Jun 22 22:41:14 UTC 2022

Modified Files:
src/usr.bin/stat: stat.1

Log Message:
stat(1): Misc fixes.


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 src/usr.bin/stat/stat.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/stat

2022-06-22 Thread Valeriy E. Ushakov
Module Name:src
Committed By:   uwe
Date:   Wed Jun 22 22:41:14 UTC 2022

Modified Files:
src/usr.bin/stat: stat.1

Log Message:
stat(1): Misc fixes.


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 src/usr.bin/stat/stat.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/stat/stat.1
diff -u src/usr.bin/stat/stat.1:1.43 src/usr.bin/stat/stat.1:1.44
--- src/usr.bin/stat/stat.1:1.43	Wed Jun 22 22:25:23 2022
+++ src/usr.bin/stat/stat.1	Wed Jun 22 22:41:13 2022
@@ -1,4 +1,4 @@
-.\"	$NetBSD: stat.1,v 1.43 2022/06/22 22:25:23 wiz Exp $
+.\"	$NetBSD: stat.1,v 1.44 2022/06/22 22:41:13 uwe Exp $
 .\"
 .\" Copyright (c) 2002-2011 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -75,9 +75,9 @@ The
 (and also the
 .Sq path name )
 in this case is
-.Dq \&(stdin) .
+.Ql \&(stdin) .
 The file number
-.Pq Dq %@
+.Pq Ql %@
 will be zero.
 .Pp
 Otherwise the information displayed is obtained by calling
@@ -108,23 +108,23 @@ and
 fields, in that order.
 .Pp
 The options are as follows:
-.Bl -tag -width XFXformatXXX
+.Bl -tag -width Fl
 .It Fl F
 As in
 .Xr ls 1 ,
 display a slash
-.Pq Sq /
+.Pq Ql /
 immediately after each pathname that is a directory, an
 asterisk
-.Pq Sq *
+.Pq Ql *
 after each that is executable, an at sign
-.Pq Sq @
+.Pq Ql @
 after each symbolic link, a percent sign
-.Pq Sq %
+.Pq Ql %
 after each whiteout, an equal sign
-.Pq Sq =
+.Pq Ql =
 after each socket, and a vertical bar
-.Pq Sq \&|
+.Pq Ql \&|
 after each that is a FIFO.
 The use of
 .Fl F
@@ -184,14 +184,20 @@ FMT="$FMT st_flags=%f"
 stat -t %s -f "$FMT" .
 .Ed
 .Pp
-The timefmt may be altered from the default for
+The
+.Ar timefmt
+may be altered from the default for
 .Fl s
-.Pq Dq \&%s ,
+.Pq Ql \&%s
 by also using the
 .Fl t
 option.
-Note that if you use a timefmt that contains embedded whitespace or shell
-meta-characters, or if the shell's IFS is set to a non-standard value,
+Note that if you use a
+.Ar timefmt
+that contains embedded whitespace or shell
+meta-characters, or if the shell's
+.Dv IFS
+is set to a non-standard value,
 you will need to
 include appropriate quoting in the
 .Fl t
@@ -206,7 +212,9 @@ using the specified format.
 This format is
 passed directly to
 .Xr strftime 3
-with the extension that %f prints nanoseconds if available.
+with the extension that
+.Ql %f
+prints nanoseconds if available.
 .It Fl x
 Display information in a more verbose way as seen from some Linux
 distributions.
@@ -235,7 +243,7 @@ or the current file number in the argume
 Otherwise the string is examined for the following:
 .Pp
 Any of the following optional flags in any order:
-.Bl -tag -width Ds
+.Bl -tag -width Cm
 .It Cm #
 Selects an alternate output form for string, octal and hexadecimal output.
 String output will be encoded in
@@ -243,7 +251,7 @@ String output will be encoded in
 style.
 Octal output will have a leading zero.
 Non-zero hexadecimal output will have
-.Dq 0x
+.Ql 0x
 prepended to it.
 .It Cm +
 Asserts that a sign indicating whether a number is positive or negative
@@ -262,22 +270,20 @@ overrides a space if both are used.
 .El
 .Pp
 Then followed by the following fields in the following order:
-.Bl -tag -width Ds
-.It Cm size
+.Bl -tag -width Ar
+.It Ar size
 An optional decimal digit string specifying the minimum field width.
-Note that a leading zero
-.Pq Sq 0
-is treated as the
-.Sq 0
+Note that a leading zero is treated as the
+.Sq Cm 0
 flag (above), subsequent embedded zeroes are part of the
-.Cm size .
-.It Cm prec
+.Ar size .
+.It Ar prec
 An optional precision composed of a decimal point
 .Sq Cm \&.
 and a decimal digit string that indicates the maximum string length,
 the number of digits to appear after the decimal point in floating point
 output, or the minimum number of digits to appear in other numeric output.
-.It Cm fmt
+.It Ar fmt
 An optional output format specifier which is one of
 .Cm D ,
 .Cm O ,
@@ -301,20 +307,22 @@ The special output format specifier
 .Cm S
 may be used to indicate that the output, if
 applicable, should be in string format.
-May be used in combination with
-.Bl -tag -width Ds
-.It Cm amc
+May be used in combination with the following field specifiers:
+.Bl -tag -width Cm
+.It Cm a , m , c
 Display date in
 .Xr strftime 3
-format with the extension that %f prints nanoseconds if available.
-.It Cm dr
+format with the extension that
+.Ql %f
+prints nanoseconds if available.
+.It Cm d , r
 Display actual device name.
-.It Cm gu
+.It Cm g , u
 Display group or user name.
 .It Cm p
 Display the mode of
 .Ar file
-as in
+symbolically, as in
 .Ic ls -lTd .
 .It Cm N
 Displays the name of
@@ -322,8 +330,10 @@ Displays the name of
 .It Cm T
 Displays the type of
 .Ar file .
-.It Cm RY
-Insert a `` -> '' into the output.
+.It Cm R , Y
+Insert a
+.Sq Li \~->\~ \" .Ql, but force quotes even in PS output
+into the output.
 Note that the default output 

CVS commit: src/usr.bin/stat

2022-06-22 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Wed Jun 22 22:25:23 UTC 2022

Modified Files:
src/usr.bin/stat: stat.1

Log Message:
Use \(em, fix macro usage


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 src/usr.bin/stat/stat.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/stat/stat.1
diff -u src/usr.bin/stat/stat.1:1.42 src/usr.bin/stat/stat.1:1.43
--- src/usr.bin/stat/stat.1:1.42	Wed Jun 22 18:20:30 2022
+++ src/usr.bin/stat/stat.1	Wed Jun 22 22:25:23 2022
@@ -1,4 +1,4 @@
-.\"	$NetBSD: stat.1,v 1.42 2022/06/22 18:20:30 kre Exp $
+.\"	$NetBSD: stat.1,v 1.43 2022/06/22 22:25:23 wiz Exp $
 .\"
 .\" Copyright (c) 2002-2011 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -347,7 +347,7 @@ It can be one of the following:
 .Bl -tag -width Ds
 .It Cm H
 .Dq High
--- depending on the
+\(em depending on the
 .Cm datum :
 .Bl -tag -compact -width door
 .It Cm d , r
@@ -368,7 +368,7 @@ File size, rounded to the nearest gigaby
 .El
 .It Cm M
 .Dq Middle
--- depending on the
+\(em depending on the
 .Cm datum :
 .Bl -tag -compact -width door
 .It Cm p
@@ -385,7 +385,7 @@ File size, rounded to the nearest megaby
 .El
 .It Cm L
 .Dq Low
--- depending on the
+\(em depending on the
 .Cm datum :
 .Bl -tag -compact -width door
 .It Cm r , d
@@ -534,7 +534,7 @@ If no options are specified, the default
 .Ed
 .Pp
 Thus:
-.Bd -literal -offset indent compact
+.Bd -literal -offset indent -compact
 > stat /tmp/bar
 0 78852 -rw-r--r-- 1 root wheel \(mi1 0 "Jul  8 10:26:03 2004" "Jul  8 10:26:03 2004" "Jul  8 10:28:13 2004" "Jan  1 09:00:00 1970" 16384 0 0 /tmp/bar
 .Ed



CVS commit: src/usr.bin/stat

2022-06-22 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Wed Jun 22 22:25:23 UTC 2022

Modified Files:
src/usr.bin/stat: stat.1

Log Message:
Use \(em, fix macro usage


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 src/usr.bin/stat/stat.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/stat

2022-06-22 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Wed Jun 22 22:25:09 UTC 2022

Modified Files:
src/usr.bin/stat: readlink.1

Log Message:
Remove dot at end of SEE ALSO.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/stat/readlink.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/stat/readlink.1
diff -u src/usr.bin/stat/readlink.1:1.3 src/usr.bin/stat/readlink.1:1.4
--- src/usr.bin/stat/readlink.1:1.3	Wed Jun 22 19:27:47 2022
+++ src/usr.bin/stat/readlink.1	Wed Jun 22 22:25:08 2022
@@ -1,4 +1,4 @@
-.\"	$NetBSD: readlink.1,v 1.3 2022/06/22 19:27:47 uwe Exp $
+.\"	$NetBSD: readlink.1,v 1.4 2022/06/22 22:25:08 wiz Exp $
 .\"
 .\" Copyright (c) 2002-2011 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -94,7 +94,7 @@ and
 .Sh SEE ALSO
 .Xr stat 1 ,
 .Xr lstat 2 ,
-.Xr readlink 2 .
+.Xr readlink 2
 .Sh HISTORY
 The
 .Nm



CVS commit: src/usr.bin/stat

2022-06-22 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Wed Jun 22 22:25:09 UTC 2022

Modified Files:
src/usr.bin/stat: readlink.1

Log Message:
Remove dot at end of SEE ALSO.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/stat/readlink.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/stat

2022-06-22 Thread Valeriy E. Ushakov
Module Name:src
Committed By:   uwe
Date:   Wed Jun 22 19:27:47 UTC 2022

Modified Files:
src/usr.bin/stat: readlink.1

Log Message:
readlink(1): Add italic correction.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/stat/readlink.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/stat

2022-06-22 Thread Valeriy E. Ushakov
Module Name:src
Committed By:   uwe
Date:   Wed Jun 22 19:27:47 UTC 2022

Modified Files:
src/usr.bin/stat: readlink.1

Log Message:
readlink(1): Add italic correction.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/stat/readlink.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/stat/readlink.1
diff -u src/usr.bin/stat/readlink.1:1.2 src/usr.bin/stat/readlink.1:1.3
--- src/usr.bin/stat/readlink.1:1.2	Wed Jun 22 19:18:17 2022
+++ src/usr.bin/stat/readlink.1	Wed Jun 22 19:27:47 2022
@@ -1,4 +1,4 @@
-.\"	$NetBSD: readlink.1,v 1.2 2022/06/22 19:18:17 uwe Exp $
+.\"	$NetBSD: readlink.1,v 1.3 2022/06/22 19:27:47 uwe Exp $
 .\"
 .\" Copyright (c) 2002-2011 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -82,7 +82,7 @@ This is an alternative to
 Turn off quiet mode.
 .Nm
 will display errors about
-.Ar file Ns s
+.Ar file\^ Ns s
 for which
 .Xr lstat 2
 fails.



CVS commit: src/usr.bin/stat

2022-06-22 Thread Valeriy E. Ushakov
Module Name:src
Committed By:   uwe
Date:   Wed Jun 22 19:18:17 UTC 2022

Modified Files:
src/usr.bin/stat: readlink.1

Log Message:
readlink(1): Add missing .El, use non-random .Bl -width


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/stat/readlink.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/stat/readlink.1
diff -u src/usr.bin/stat/readlink.1:1.1 src/usr.bin/stat/readlink.1:1.2
--- src/usr.bin/stat/readlink.1:1.1	Wed Jun 22 18:02:43 2022
+++ src/usr.bin/stat/readlink.1	Wed Jun 22 19:18:17 2022
@@ -1,4 +1,4 @@
-.\"	$NetBSD: readlink.1,v 1.1 2022/06/22 18:02:43 kre Exp $
+.\"	$NetBSD: readlink.1,v 1.2 2022/06/22 19:18:17 uwe Exp $
 .\"
 .\" Copyright (c) 2002-2011 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -61,7 +61,7 @@ return the absolute pathname correspondi
 In this case, the argument does not need to be a symbolic link.
 .Pp
 The options are as follows:
-.Bl -tag -width XFXXX
+.Bl -tag -width Fl
 .It Fl f
 Canonicalize the pathname of
 .Ar file ,
@@ -90,6 +90,7 @@ This is the inverse of
 .Fl q
 and
 .Fl s .
+.El
 .Sh SEE ALSO
 .Xr stat 1 ,
 .Xr lstat 2 ,



CVS commit: src/usr.bin/stat

2022-06-22 Thread Valeriy E. Ushakov
Module Name:src
Committed By:   uwe
Date:   Wed Jun 22 19:18:17 UTC 2022

Modified Files:
src/usr.bin/stat: readlink.1

Log Message:
readlink(1): Add missing .El, use non-random .Bl -width


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/stat/readlink.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/stat

2022-06-22 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Wed Jun 22 18:20:30 UTC 2022

Modified Files:
src/usr.bin/stat: stat.1 stat.c

Log Message:
Some corrections to stat to make it more reasonable, and comply with
the man page, in particular, in one of the EXAMPLES it is claimed:

 This example produces output very similar to that from find ... -ls
 (except that find(1) displays the time in a different format, and find(1)
 sometimes adds one or more spaces after the comma in “major,minor” for
 device nodes):

and then uses %9Z in the format, but conveniently does not use a
device file to demonstrate.

If it had, the result would have been:

   8033  0 brw-r-1 root  operator  4,   
51 Jun  8 02:44:45 2022 /dev/sd3

Note the spaces which were claimed to exist (sometimes) in find(1) output
but not with stat.   Oops.

Omitting those spaces seems like a good idea, so does using the same
field width for the result in both cases, rather than producing 9 chars
in the ordinary file case, and 19 (2 * 9 + 1) in the device case (for %9Z).

Now we will get:

   8033  0 brw-r-1 root  operator 4,51   
Jun  8 02:44:45 2022 /dev/sd3

While here, also make the file number (%@) when reading stdin be 0, it is
not the 1st file in the arg list.

Some (very minor) KNF applied at the same time.

In stat.1 make these changes explicit.


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 src/usr.bin/stat/stat.1
cvs rdiff -u -r1.47 -r1.48 src/usr.bin/stat/stat.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/stat/stat.1
diff -u src/usr.bin/stat/stat.1:1.41 src/usr.bin/stat/stat.1:1.42
--- src/usr.bin/stat/stat.1:1.41	Wed Jun 22 18:02:43 2022
+++ src/usr.bin/stat/stat.1	Wed Jun 22 18:20:30 2022
@@ -1,4 +1,4 @@
-.\"	$NetBSD: stat.1,v 1.41 2022/06/22 18:02:43 kre Exp $
+.\"	$NetBSD: stat.1,v 1.42 2022/06/22 18:20:30 kre Exp $
 .\"
 .\" Copyright (c) 2002-2011 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -76,6 +76,9 @@ The
 .Sq path name )
 in this case is
 .Dq \&(stdin) .
+The file number
+.Pq Dq %@
+will be zero.
 .Pp
 Otherwise the information displayed is obtained by calling
 .Xr lstat 2
@@ -487,11 +490,17 @@ from the
 .Fa st_rdev
 field for character or block special devices
 (that is,
-.Dq %Hr,%Lr )
+.Dq %Hr,%-Lr )
 and gives size output
 .Pq Fa st_size
 .Pq Dq %z
 for all others.
+A specified field width applies to the overall result
+(approximately half each for the two device file sub-fields),
+but precision, output format, and flags are used separately for
+each conversion made (but note the
+.Sq Fl
+in the %Lr conversion.)
 .El
 .El
 .Pp

Index: src/usr.bin/stat/stat.c
diff -u src/usr.bin/stat/stat.c:1.47 src/usr.bin/stat/stat.c:1.48
--- src/usr.bin/stat/stat.c:1.47	Fri Aug 27 18:11:07 2021
+++ src/usr.bin/stat/stat.c	Wed Jun 22 18:20:30 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: stat.c,v 1.47 2021/08/27 18:11:07 rillig Exp $ */
+/*	$NetBSD: stat.c,v 1.48 2022/06/22 18:20:30 kre Exp $ */
 
 /*
  * Copyright (c) 2002-2011 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 #include 
 #if !defined(lint)
-__RCSID("$NetBSD: stat.c,v 1.47 2021/08/27 18:11:07 rillig Exp $");
+__RCSID("$NetBSD: stat.c,v 1.48 2022/06/22 18:20:30 kre Exp $");
 #endif
 
 #if ! HAVE_NBTOOL_CONFIG_H
@@ -322,9 +322,10 @@ main(int argc, char *argv[])
 
 	errs = 0;
 	do {
-		if (argc == 0)
+		if (argc == 0) {
+			fn = 0;
 			rc = fstat(STDIN_FILENO, );
-		else if (usestat) {
+		} else if (usestat) {
 			/*
 			 * Try stat() and if it fails, fall back to
 			 * lstat() just in case we're examining a
@@ -334,8 +335,7 @@ main(int argc, char *argv[])
 			errno == ENOENT &&
 			(rc = lstat(argv[0], )) == -1)
 errno = ENOENT;
-		}
-		else
+		} else
 			rc = lstat(argv[0], );
 
 		if (rc == -1) {
@@ -345,8 +345,7 @@ main(int argc, char *argv[])
 warn("%s: %s",
 argc == 0 ? "(stdin)" : argv[0],
 usestat ? "stat" : "lstat");
-		}
-		else
+		} else
 			output(, argv[0], statfmt, fn, nonl, quiet);
 
 		argv++;
@@ -1030,17 +1029,19 @@ format1(const struct stat *st,
 			char majdev[20], mindev[20];
 			int l1, l2;
 
+			if (size == 0)		/* avoid -1/2 */
+size++;		/* 1/2 == 0/2 so this is safe */
 			l1 = format1(st,
 			file,
 			fmt, flen,
 			majdev, sizeof(majdev),
-			flags, size, prec,
+			flags, (size - 1) / 2, prec,
 			ofmt, HIGH_PIECE, SHOW_st_rdev, quiet);
 			l2 = format1(st,
 			file,
 			fmt, flen,
 			mindev, sizeof(mindev),
-			flags, size, prec,
+			flags | FLAG_MINUS , size / 2, prec,
 			ofmt, LOW_PIECE, SHOW_st_rdev, quiet);
 			return (snprintf(buf, blen, "%.*s,%.*s",
 			l1, majdev, l2, mindev));



CVS commit: src/usr.bin/stat

2022-06-22 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Wed Jun 22 18:20:30 UTC 2022

Modified Files:
src/usr.bin/stat: stat.1 stat.c

Log Message:
Some corrections to stat to make it more reasonable, and comply with
the man page, in particular, in one of the EXAMPLES it is claimed:

 This example produces output very similar to that from find ... -ls
 (except that find(1) displays the time in a different format, and find(1)
 sometimes adds one or more spaces after the comma in “major,minor” for
 device nodes):

and then uses %9Z in the format, but conveniently does not use a
device file to demonstrate.

If it had, the result would have been:

   8033  0 brw-r-1 root  operator  4,   
51 Jun  8 02:44:45 2022 /dev/sd3

Note the spaces which were claimed to exist (sometimes) in find(1) output
but not with stat.   Oops.

Omitting those spaces seems like a good idea, so does using the same
field width for the result in both cases, rather than producing 9 chars
in the ordinary file case, and 19 (2 * 9 + 1) in the device case (for %9Z).

Now we will get:

   8033  0 brw-r-1 root  operator 4,51   
Jun  8 02:44:45 2022 /dev/sd3

While here, also make the file number (%@) when reading stdin be 0, it is
not the 1st file in the arg list.

Some (very minor) KNF applied at the same time.

In stat.1 make these changes explicit.


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 src/usr.bin/stat/stat.1
cvs rdiff -u -r1.47 -r1.48 src/usr.bin/stat/stat.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/stat

2022-06-22 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Wed Jun 22 18:02:43 UTC 2022

Modified Files:
src/usr.bin/stat: Makefile stat.1
Added Files:
src/usr.bin/stat: readlink.1

Log Message:
Divide stat.1 into stat.1 (now only includes stat(1)) and readlink.1

Apologies to cvs commit purists, but making this division required
line by line reading of the man pages, and I simply could not resist
also correcting some errors, addressing some omissions, improving some
wording ... all at the same time.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/usr.bin/stat/Makefile
cvs rdiff -u -r0 -r1.1 src/usr.bin/stat/readlink.1
cvs rdiff -u -r1.40 -r1.41 src/usr.bin/stat/stat.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/stat/Makefile
diff -u src/usr.bin/stat/Makefile:1.11 src/usr.bin/stat/Makefile:1.12
--- src/usr.bin/stat/Makefile:1.11	Sun Sep 29 23:45:01 2019
+++ src/usr.bin/stat/Makefile	Wed Jun 22 18:02:43 2022
@@ -1,10 +1,10 @@
-#	$NetBSD: Makefile,v 1.11 2019/09/29 23:45:01 mrg Exp $
+#	$NetBSD: Makefile,v 1.12 2022/06/22 18:02:43 kre Exp $
 
 PROG=	stat
 
 .if !defined(HOSTPROG)
 LINKS=	${BINDIR}/stat ${BINDIR}/readlink
-MLINKS=	stat.1 readlink.1
+MAN=	stat.1 readlink.1
 .endif
 
 .include 

Index: src/usr.bin/stat/stat.1
diff -u src/usr.bin/stat/stat.1:1.40 src/usr.bin/stat/stat.1:1.41
--- src/usr.bin/stat/stat.1:1.40	Wed Sep 20 08:57:02 2017
+++ src/usr.bin/stat/stat.1	Wed Jun 22 18:02:43 2022
@@ -1,4 +1,4 @@
-.\"	$NetBSD: stat.1,v 1.40 2017/09/20 08:57:02 wiz Exp $
+.\"	$NetBSD: stat.1,v 1.41 2022/06/22 18:02:43 kre Exp $
 .\"
 .\" Copyright (c) 2002-2011 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -27,12 +27,11 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd September 19, 2017
+.Dd June 22, 2022
 .Dt STAT 1
 .Os
 .Sh NAME
-.Nm stat ,
-.Nm readlink
+.Nm stat
 .Nd display file status
 .Sh SYNOPSIS
 .Nm
@@ -46,42 +45,46 @@
 .Oc
 .Op Fl t Ar timefmt
 .Op Ar
-.Nm readlink
-.Op Fl fnqsv
-.Op Ar
 .Sh DESCRIPTION
 The
 .Nm
-utility displays information about the file pointed to by
+utility displays information about each file given by
 .Ar file .
-Read, write, or execute permissions of the named file are not required, but
+Read, write, or execute permissions for the named file are not required, but
 all directories listed in the pathname leading to the file must be
 searchable.
-If no argument is given,
+.Pp
+If no
+.Ar file
+argument is given,
 .Nm
 displays information about the file descriptor for standard input.
+In this case the
+.Fl L
+option is ignored, and
+.Nm
+uses
+.Xr fstat 2
+rather than
+.Xr lstat 2
+or
+.Xr stat 2
+to obtain information.
+The
+.Sq file name
+(and also the
+.Sq path name )
+in this case is
+.Dq \&(stdin) .
 .Pp
-When invoked as
-.Nm readlink ,
-only the target of the symbolic link is printed.
-If the given argument is not a symbolic link and the
-.Fl f
-option is not specified,
-.Nm readlink
-will print nothing and exit with an error.
-If the
-.Fl f
-option is specified, the output is canonicalized by following every symlink
-in every component of the given path recursively.
-.Nm readlink
-will resolve both absolute and relative paths, and return the absolute pathname
-corresponding to
-.Ar file .
-In this case, the argument does not need to be a symbolic link.
-.Pp
-The information displayed is obtained by calling
+Otherwise the information displayed is obtained by calling
 .Xr lstat 2
-with the given argument and evaluating the returned structure.
+(or
+.Xr stat 2
+with
+.Fl L )
+with each given argument in turn and evaluating the returned structure.
+.Pp
 The default format displays the
 .Fa st_dev ,
 .Fa st_ino ,
@@ -138,7 +141,9 @@ The information reported by
 .Nm
 will refer to the target of
 .Ar file ,
-if file is a symbolic link, and not to
+if
+.Ar file
+is a symbolic link, rather than to
 .Ar file
 itself.
 .It Fl l
@@ -149,13 +154,13 @@ format.
 Do not force a newline to appear at the end of each piece of output.
 .It Fl q
 Suppress failure messages if calls to
-.Xr stat 2
+.Xr fstat 2 ,
+.Xr lstat 2 ,
+.Xr readlink 2 ,
+.Xr realpath 3 ,
 or
-.Xr lstat 2
+.Xr stat 2
 fail.
-When run as
-.Nm readlink ,
-error messages are automatically suppressed.
 .It Fl r
 Display raw information.
 That is, for all the fields in the stat-structure,
@@ -163,42 +168,57 @@ display the raw, numerical value (for ex
 epoch, etc.)
 .It Fl s
 Display information in
-.Dq shell output ,
+.Dq shell command
+output format,
 suitable for initializing variables.
-When run as
-.Nm readlink ,
-suppress error messages.
 This is equivalent to specifying
 .Bd -literal
-FMT="st_dev=%d st_ino=%i st_mode=%#p st_nlink=%l st_uid=%u st_gid=%g"
-FMT="$FMT st_rdev=%r st_size=%z st_atime=%Sa st_mtime=%Sm st_ctime=%Sc"
-FMT="$FMT st_birthtime=%SB st_blksize=%k st_blocks=%b st_flags=%f"

CVS commit: src/usr.bin/stat

2022-06-22 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Wed Jun 22 18:02:43 UTC 2022

Modified Files:
src/usr.bin/stat: Makefile stat.1
Added Files:
src/usr.bin/stat: readlink.1

Log Message:
Divide stat.1 into stat.1 (now only includes stat(1)) and readlink.1

Apologies to cvs commit purists, but making this division required
line by line reading of the man pages, and I simply could not resist
also correcting some errors, addressing some omissions, improving some
wording ... all at the same time.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/usr.bin/stat/Makefile
cvs rdiff -u -r0 -r1.1 src/usr.bin/stat/readlink.1
cvs rdiff -u -r1.40 -r1.41 src/usr.bin/stat/stat.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/stat

2021-08-27 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Aug 27 18:11:07 UTC 2021

Modified Files:
src/usr.bin/stat: stat.c

Log Message:
stat: fix undefined behavior when calling ctype functions

lint says: warning: argument to 'function from ' must be cast
to 'unsigned char', not to 'unsigned int' [342]


To generate a diff of this commit:
cvs rdiff -u -r1.46 -r1.47 src/usr.bin/stat/stat.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/stat/stat.c
diff -u src/usr.bin/stat/stat.c:1.46 src/usr.bin/stat/stat.c:1.47
--- src/usr.bin/stat/stat.c:1.46	Mon Sep  7 00:46:38 2020
+++ src/usr.bin/stat/stat.c	Fri Aug 27 18:11:07 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: stat.c,v 1.46 2020/09/07 00:46:38 mrg Exp $ */
+/*	$NetBSD: stat.c,v 1.47 2021/08/27 18:11:07 rillig Exp $ */
 
 /*
  * Copyright (c) 2002-2011 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 #include 
 #if !defined(lint)
-__RCSID("$NetBSD: stat.c,v 1.46 2020/09/07 00:46:38 mrg Exp $");
+__RCSID("$NetBSD: stat.c,v 1.47 2021/08/27 18:11:07 rillig Exp $");
 #endif
 
 #if ! HAVE_NBTOOL_CONFIG_H
@@ -469,9 +469,9 @@ output(const struct stat *st, const char
 		} while (1/*CONSTCOND*/);
 
 		size = -1;
-		if (isdigit((unsigned)*statfmt)) {
+		if (isdigit((unsigned char)*statfmt)) {
 			size = 0;
-			while (isdigit((unsigned)*statfmt)) {
+			while (isdigit((unsigned char)*statfmt)) {
 size = (size * 10) + (*statfmt - '0');
 statfmt++;
 if (size < 0)
@@ -484,7 +484,7 @@ output(const struct stat *st, const char
 			statfmt++;
 
 			prec = 0;
-			while (isdigit((unsigned)*statfmt)) {
+			while (isdigit((unsigned char)*statfmt)) {
 prec = (prec * 10) + (*statfmt - '0');
 statfmt++;
 if (prec < 0)



CVS commit: src/usr.bin/stat

2021-08-27 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Aug 27 18:11:07 UTC 2021

Modified Files:
src/usr.bin/stat: stat.c

Log Message:
stat: fix undefined behavior when calling ctype functions

lint says: warning: argument to 'function from ' must be cast
to 'unsigned char', not to 'unsigned int' [342]


To generate a diff of this commit:
cvs rdiff -u -r1.46 -r1.47 src/usr.bin/stat/stat.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



Re: CVS commit: src/usr.bin/stat

2010-11-24 Thread Christos Zoulas
In article 20101124225754.6201e17...@cvs.netbsd.org,
David A. Holland source-changes-d@NetBSD.org wrote:

-  (void)snprintf(tmp, sizeof(tmp), %dd, prec  9 ? 9 : prec);
+  (void)snprintf(tmp, sizeof(tmp), %dld, prec  9 ? 9 : prec);

perhaps %dlld?

   (void)strcat(lfmt, tmp);

-  l = snprintf(buf, blen, lfmt, secs, nsecs);
+  l = snprintf(buf, blen, lfmt, (long long)secs, nsecs);

christos



Re: CVS commit: src/usr.bin/stat

2010-11-24 Thread David Holland
On Wed, Nov 24, 2010 at 11:11:36PM +, Christos Zoulas wrote:
  -   (void)snprintf(tmp, sizeof(tmp), %dd, prec  9 ? 9 : prec);
  +   (void)snprintf(tmp, sizeof(tmp), %dld, prec  9 ? 9 : prec);
  
  perhaps %dlld?

Nope, that's the nsecs, which are long.

I'm sort of inclined to rework the whole thing to make it clearer, but
I'm not sure it'd actually be an improvement.

-- 
David A. Holland
dholl...@netbsd.org


Re: CVS commit: src/usr.bin/stat

2010-11-24 Thread Christos Zoulas
On Nov 24, 11:49pm, dholland-sourcechan...@netbsd.org (David Holland) wrote:
-- Subject: Re: CVS commit: src/usr.bin/stat

| On Wed, Nov 24, 2010 at 11:11:36PM +, Christos Zoulas wrote:
|   - (void)snprintf(tmp, sizeof(tmp), %dd, prec  9 ? 9 : prec);
|   + (void)snprintf(tmp, sizeof(tmp), %dld, prec  9 ? 9 : prec);
|   
|   perhaps %dlld?
| 
| Nope, that's the nsecs, which are long.
| 
| I'm sort of inclined to rework the whole thing to make it clearer, but
| I'm not sure it'd actually be an improvement.

Ok, just making sure :-)

christos