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.



CVS commit: src/usr.bin/stat

2020-09-06 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Mon Sep  7 00:46:38 UTC 2020

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

Log Message:
avoid a GCC stringop truncate warning.


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 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.45 src/usr.bin/stat/stat.c:1.46
--- src/usr.bin/stat/stat.c:1.45	Fri Oct  4 11:12:16 2019
+++ src/usr.bin/stat/stat.c	Mon Sep  7 00:46:38 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: stat.c,v 1.45 2019/10/04 11:12:16 mrg Exp $ */
+/*	$NetBSD: stat.c,v 1.46 2020/09/07 00:46:38 mrg Exp $ */
 
 /*
  * Copyright (c) 2002-2011 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 #include 
 #if !defined(lint)
-__RCSID("$NetBSD: stat.c,v 1.45 2019/10/04 11:12:16 mrg Exp $");
+__RCSID("$NetBSD: stat.c,v 1.46 2020/09/07 00:46:38 mrg Exp $");
 #endif
 
 #if ! HAVE_NBTOOL_CONFIG_H
@@ -1072,6 +1072,8 @@ format1(const struct stat *st,
 	if ((flags & FLAG_POUND) != 0 && ofmt == FMTF_STRING) {
 		flags &= !FLAG_POUND;
 		strncpy(visbuf, sdata, prefixlen);
+		/* Avoid GCC warnings. */
+		visbuf[prefixlen] = 0;
 		strnvis(visbuf + prefixlen, sizeof(visbuf) - prefixlen,
 		sdata + prefixlen, VIS_WHITE | VIS_OCTAL | VIS_CSTYLE);
 		sdata = visbuf;



CVS commit: src/usr.bin/stat

2020-09-06 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Mon Sep  7 00:46:38 UTC 2020

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

Log Message:
avoid a GCC stringop truncate warning.


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 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

2019-02-04 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Mon Feb  4 10:03:16 UTC 2019

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

Log Message:
rework the previous to only apply if !HOSTPROG


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/stat/Makefile

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.9 src/usr.bin/stat/Makefile:1.10
--- src/usr.bin/stat/Makefile:1.9	Mon Feb  4 09:51:47 2019
+++ src/usr.bin/stat/Makefile	Mon Feb  4 10:03:16 2019
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.9 2019/02/04 09:51:47 mrg Exp $
+#	$NetBSD: Makefile,v 1.10 2019/02/04 10:03:16 mrg Exp $
 
 PROG=	stat
 
@@ -10,7 +10,7 @@ MLINKS=	stat.1 readlink.1
 .include 
 
 # Has fallthru comment that is missed
-.if defined(HAVE_GCC) && ${HAVE_GCC} == 7 && ${ACTIVE_CC} == "gcc"
+.if !defined(HOSTPROG) && defined(HAVE_GCC) && ${HAVE_GCC} == 7 && ${ACTIVE_CC} == "gcc"
 COPTS.stat.c+=	-Wno-error=implicit-fallthrough
 .endif
 



CVS commit: src/usr.bin/stat

2019-02-04 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Mon Feb  4 10:03:16 UTC 2019

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

Log Message:
rework the previous to only apply if !HOSTPROG


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/stat/Makefile

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

2019-02-04 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Mon Feb  4 08:07:33 UTC 2019

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

Log Message:
avoid a potential buffer truncation.


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 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

2019-02-04 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Mon Feb  4 08:07:33 UTC 2019

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

Log Message:
avoid a potential buffer truncation.


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 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.43 src/usr.bin/stat/stat.c:1.44
--- src/usr.bin/stat/stat.c:1.43	Thu Sep 21 22:53:19 2017
+++ src/usr.bin/stat/stat.c	Mon Feb  4 08:07:33 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: stat.c,v 1.43 2017/09/21 22:53:19 kre Exp $ */
+/*	$NetBSD: stat.c,v 1.44 2019/02/04 08:07:33 mrg Exp $ */
 
 /*
  * Copyright (c) 2002-2011 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 #include 
 #if !defined(lint)
-__RCSID("$NetBSD: stat.c,v 1.43 2017/09/21 22:53:19 kre Exp $");
+__RCSID("$NetBSD: stat.c,v 1.44 2019/02/04 08:07:33 mrg Exp $");
 #endif
 
 #if ! HAVE_NBTOOL_CONFIG_H
@@ -646,7 +646,7 @@ format1(const struct stat *st,
 	uint64_t data;
 	char *stmp, lfmt[24], tmp[20];
 	const char *sdata;
-	char smode[12], sid[12], path[PATH_MAX + 4], visbuf[PATH_MAX * 4 + 4];
+	char smode[12], sid[13], path[PATH_MAX + 4], visbuf[PATH_MAX * 4 + 4];
 	struct passwd *pw;
 	struct group *gr;
 	time_t secs;



CVS commit: src/usr.bin/stat

2017-09-21 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Thu Sep 21 22:53:19 UTC 2017

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

Log Message:
Handle the new %f (as an addition to the strftime format - -t arg)
correctly, in particular %%f does not contain the %f format, and like
all strftime conversions, %f can occur more than once (not that it is
likely to happen, but just in case...)


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 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

2017-09-21 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Thu Sep 21 22:53:19 UTC 2017

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

Log Message:
Handle the new %f (as an addition to the strftime format - -t arg)
correctly, in particular %%f does not contain the %f format, and like
all strftime conversions, %f can occur more than once (not that it is
likely to happen, but just in case...)


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 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.42 src/usr.bin/stat/stat.c:1.43
--- src/usr.bin/stat/stat.c:1.42	Thu Sep 21 18:50:08 2017
+++ src/usr.bin/stat/stat.c	Thu Sep 21 22:53:19 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: stat.c,v 1.42 2017/09/21 18:50:08 kre Exp $ */
+/*	$NetBSD: stat.c,v 1.43 2017/09/21 22:53:19 kre Exp $ */
 
 /*
  * Copyright (c) 2002-2011 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 #include 
 #if !defined(lint)
-__RCSID("$NetBSD: stat.c,v 1.42 2017/09/21 18:50:08 kre Exp $");
+__RCSID("$NetBSD: stat.c,v 1.43 2017/09/21 22:53:19 kre Exp $");
 #endif
 
 #if ! HAVE_NBTOOL_CONFIG_H
@@ -568,26 +568,62 @@ static const char *
 fmttime(char *buf, size_t len, const char *fmt, time_t secs, long nsecs)
 {
 	struct tm tm;
-	char *fmt2;
+	const char *fpb, *fp1, *fp2;	/* pointers into fmt */
+	char *fmt2 = NULL;		/* replacement fmt (if not NULL) */
+/* XXX init of next twp for stupid gcc only */
+	char *f2p = NULL;		/* ptr into fmt2 - last added */
+	size_t flen = 0;
+	size_t o;
+	int sl;
 
 	if (localtime_r(, ) == NULL) {
 		secs = 0;
 		(void)localtime_r(, );
 	}
-	if ((fmt2 = strstr(fmt, "%f")) != NULL) {
-		size_t flen = strlen(fmt) + 1024;
-		size_t o = (size_t)(fmt2 - fmt);
-
-		fmt2 = calloc(flen, 1);
-		if (fmt2 != NULL) {
-			int sl;
-
-			memcpy(fmt2, fmt, o);
-			sl = snprintf(fmt2 + o, flen - o, "%.9ld", nsecs);
-			if (sl == -1)
-sl = 0;
-			strcpy(fmt2 + sl + o, fmt + o + 2);
+	for (fp1 = fpb = fmt; (fp2 = strchr(fp1, '%')) != NULL; ) {
+		if (fp2[1] != 'f') {
+			/* make sure we don't find the 2nd '%' in "%%" */
+			fp1 = fp2 + 1 + (fp2[1] != '\0');
+			continue;
+		}
+		if (fmt2 == NULL) {
+			/* allow for ~100 %f's in the format ... */
+			flen = strlen(fmt) + 1024;
+
+			if ((fmt2 = calloc(flen, 1)) == NULL) {
+fp1 = fp2 + 2;
+continue;
+			}
+			f2p = fmt2;
+
+			o = (size_t)(fp2 - fpb);
+			memcpy(f2p, fpb, o);	/* must fit */
 			fmt = fmt2;
+		} else {
+			o = (size_t)(fp2 - fpb);
+			if (flen > o)
+memcpy(f2p, fpb, o);
+		}
+		if (flen < o + 10) {	/* 9 digits + \0 == 10 */
+			*f2p = '\0';
+			break;
+		}
+		f2p += o;
+		flen -= o;
+		sl = snprintf(f2p, flen, "%.9ld", nsecs);
+		if (sl == -1)
+			sl = 0;
+		f2p += sl;
+		*f2p = '\0';
+		flen -= sl;
+		fp1 = fp2 + 2;
+		fpb = fp1;
+	}
+	if (fmt2 != NULL) {
+		o = strlen(fpb);
+		if (flen > o) {
+			memcpy(f2p, fpb, o);
+			f2p[o] = '\0';
 		}
 	}
 
@@ -785,7 +821,6 @@ format1(const struct stat *st,
 		data = secs;
 		sdata = fmttime(path, sizeof(path), timefmt, secs, nsecs);
 
-		sdata = path;
 		formats = FMTF_DECIMAL | FMTF_OCTAL | FMTF_UNSIGNED | FMTF_HEX |
 		FMTF_FLOAT | FMTF_STRING;
 		if (ofmt == 0)



CVS commit: src/usr.bin/stat

2017-09-21 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Thu Sep 21 18:50:08 UTC 2017

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

Log Message:
KNF, and since this gets compiled as a tool, avoid C99 declarations.


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 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.41 src/usr.bin/stat/stat.c:1.42
--- src/usr.bin/stat/stat.c:1.41	Wed Sep 20 17:45:25 2017
+++ src/usr.bin/stat/stat.c	Thu Sep 21 18:50:08 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: stat.c,v 1.41 2017/09/20 17:45:25 kre Exp $ */
+/*	$NetBSD: stat.c,v 1.42 2017/09/21 18:50:08 kre Exp $ */
 
 /*
  * Copyright (c) 2002-2011 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 #include 
 #if !defined(lint)
-__RCSID("$NetBSD: stat.c,v 1.41 2017/09/20 17:45:25 kre Exp $");
+__RCSID("$NetBSD: stat.c,v 1.42 2017/09/21 18:50:08 kre Exp $");
 #endif
 
 #if ! HAVE_NBTOOL_CONFIG_H
@@ -569,6 +569,7 @@ fmttime(char *buf, size_t len, const cha
 {
 	struct tm tm;
 	char *fmt2;
+
 	if (localtime_r(, ) == NULL) {
 		secs = 0;
 		(void)localtime_r(, );
@@ -576,10 +577,13 @@ fmttime(char *buf, size_t len, const cha
 	if ((fmt2 = strstr(fmt, "%f")) != NULL) {
 		size_t flen = strlen(fmt) + 1024;
 		size_t o = (size_t)(fmt2 - fmt);
+
 		fmt2 = calloc(flen, 1);
 		if (fmt2 != NULL) {
+			int sl;
+
 			memcpy(fmt2, fmt, o);
-			int sl = snprintf(fmt2 + o, flen - o, "%.9ld", nsecs);
+			sl = snprintf(fmt2 + o, flen - o, "%.9ld", nsecs);
 			if (sl == -1)
 sl = 0;
 			strcpy(fmt2 + sl + o, fmt + o + 2);



CVS commit: src/usr.bin/stat

2017-09-21 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Thu Sep 21 18:50:08 UTC 2017

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

Log Message:
KNF, and since this gets compiled as a tool, avoid C99 declarations.


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 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

2017-09-20 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Wed Sep 20 17:45:25 UTC 2017

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

Log Message:
Set the default time format for linux mode (-x) in the correct place,
so it only applies to -x (in particular, not to -s) and only if another
time format has not been explicitly selected (earlier in the arg list).

With luck, this will make lots of tests, which depended upon "stat -s"
actually generating correct sh assignment statements, go back to working again.


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 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.40 src/usr.bin/stat/stat.c:1.41
--- src/usr.bin/stat/stat.c:1.40	Wed Sep 20 01:23:37 2017
+++ src/usr.bin/stat/stat.c	Wed Sep 20 17:45:25 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: stat.c,v 1.40 2017/09/20 01:23:37 christos Exp $ */
+/*	$NetBSD: stat.c,v 1.41 2017/09/20 17:45:25 kre Exp $ */
 
 /*
  * Copyright (c) 2002-2011 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 #include 
 #if !defined(lint)
-__RCSID("$NetBSD: stat.c,v 1.40 2017/09/20 01:23:37 christos Exp $");
+__RCSID("$NetBSD: stat.c,v 1.41 2017/09/20 17:45:25 kre Exp $");
 #endif
 
 #if ! HAVE_NBTOOL_CONFIG_H
@@ -265,7 +265,6 @@ main(int argc, char *argv[])
 errx(1, "can't use format '%c' with '%c'",
 fmtchar, ch);
 			fmtchar = ch;
-			timefmt = "%Y-%m-%d %H:%M:%S.%f %z";
 			break;
 		case 't':
 			timefmt = optarg;
@@ -311,7 +310,7 @@ main(int argc, char *argv[])
 	case 'x':
 		statfmt = LINUX_FORMAT;
 		if (timefmt == NULL)
-			timefmt = "%c";
+			timefmt = "%Y-%m-%d %H:%M:%S.%f %z";
 		break;
 	default:
 		usage(synopsis);



CVS commit: src/usr.bin/stat

2017-09-20 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Wed Sep 20 17:45:25 UTC 2017

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

Log Message:
Set the default time format for linux mode (-x) in the correct place,
so it only applies to -x (in particular, not to -s) and only if another
time format has not been explicitly selected (earlier in the arg list).

With luck, this will make lots of tests, which depended upon "stat -s"
actually generating correct sh assignment statements, go back to working again.


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 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

2017-09-20 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Wed Sep 20 08:57:02 UTC 2017

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

Log Message:
whitespace fixes, use Xr.


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 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

2017-09-20 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Wed Sep 20 08:57:02 UTC 2017

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

Log Message:
whitespace fixes, use Xr.


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 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.39 src/usr.bin/stat/stat.1:1.40
--- src/usr.bin/stat/stat.1:1.39	Tue Sep 19 21:45:28 2017
+++ src/usr.bin/stat/stat.1	Wed Sep 20 08:57:02 2017
@@ -1,4 +1,4 @@
-.\"	$NetBSD: stat.1,v 1.39 2017/09/19 21:45:28 christos Exp $
+.\"	$NetBSD: stat.1,v 1.40 2017/09/20 08:57:02 wiz Exp $
 .\"
 .\" Copyright (c) 2002-2011 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -183,7 +183,7 @@ output remains valid.
 Display timestamps using the specified format.
 This format is
 passed directly to
-.Xr strftime 3 
+.Xr strftime 3
 with the extension that %f prints nanoseconds if available.
 .It Fl v
 Turn off quiet mode.
@@ -275,8 +275,9 @@ applicable, should be in string format.
 May be used in combination with
 .Bl -tag -width Ds
 .It Cm amc
-Display date in strftime(3) format
-with the extension that %f prints nanoseconds if available.
+Display date in
+.Xr strftime 3
+format with the extension that %f prints nanoseconds if available.
 .It Cm dr
 Display actual device name.
 .It Cm gu
@@ -412,7 +413,7 @@ The time
 .Ar file
 was last accessed or modified, or when the inode was last changed, or
 the birth time of the inode
-.Pq Fa st_atime , st_mtime , st_ctime, st_birthtime .
+.Pq Fa st_atime , st_mtime , st_ctime , st_birthtime .
 .It Cm z
 The size of
 .Ar file



CVS commit: src/usr.bin/stat

2017-09-19 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Sep 20 01:23:37 UTC 2017

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

Log Message:
- add the sticky bits to mode
- fix linux Birth for the havenots
code review via email from @@@


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 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.39 src/usr.bin/stat/stat.c:1.40
--- src/usr.bin/stat/stat.c:1.39	Tue Sep 19 17:45:28 2017
+++ src/usr.bin/stat/stat.c	Tue Sep 19 21:23:37 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: stat.c,v 1.39 2017/09/19 21:45:28 christos Exp $ */
+/*	$NetBSD: stat.c,v 1.40 2017/09/20 01:23:37 christos Exp $ */
 
 /*
  * Copyright (c) 2002-2011 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 #include 
 #if !defined(lint)
-__RCSID("$NetBSD: stat.c,v 1.39 2017/09/19 21:45:28 christos Exp $");
+__RCSID("$NetBSD: stat.c,v 1.40 2017/09/20 01:23:37 christos Exp $");
 #endif
 
 #if ! HAVE_NBTOOL_CONFIG_H
@@ -79,10 +79,12 @@ __RCSID("$NetBSD: stat.c,v 1.39 2017/09/
 #define DEF_B "\"%SB\" "
 #define RAW_B "%B "
 #define SHELL_B "st_birthtime=%SB "
+#define LINUX_B	"%n Birth: %SB"
 #else /* HAVE_STRUCT_STAT_ST_BIRTHTIME */
 #define DEF_B
 #define RAW_B
 #define SHELL_B
+#define LINUX_B
 #endif /* HAVE_STRUCT_STAT_ST_BIRTHTIME */
 
 #if HAVE_STRUCT_STAT_ST_ATIM
@@ -107,11 +109,11 @@ __RCSID("$NetBSD: stat.c,v 1.39 2017/09/
 	"  File: \"%N\"%n" \
 	"  Size: %-11z  Blocks: %-11b  IO Block: %-11k  %HT%n" \
 	"Device: %Hd,%Ld   Inode: %iLinks: %l%n" \
-	"  Mode: (%04OLp/%.10Sp) Uid: (%5u/%8Su)  Gid: (%5g/%8Sg)%n" \
+	"  Mode: (%Mp%03OLp/%.10Sp) Uid: (%5u/%8Su)  Gid: (%5g/%8Sg)%n" \
 	"Access: %Sa%n" \
 	"Modify: %Sm%n" \
-	"Change: %Sc%n" \
-	" Birth: %SB"
+	"Change: %Sc" \
+	LINUX_B
 
 #define TIME_FORMAT	"%b %e %T %Y"
 



CVS commit: src/usr.bin/stat

2017-09-19 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Sep 20 01:23:37 UTC 2017

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

Log Message:
- add the sticky bits to mode
- fix linux Birth for the havenots
code review via email from @@@


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 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

2017-09-19 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Sep 19 21:45:28 UTC 2017

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

Log Message:
- if st_dev/st_rdev == NODEV print -1 instead of unsigned
- update to the latest linux stat(1) format for -x (kind of)
- add the ability to display nanoseconds, like linux does
- change u_intX_t -> uintX_t


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/usr.bin/stat/stat.1 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.38 src/usr.bin/stat/stat.1:1.39
--- src/usr.bin/stat/stat.1:1.38	Mon Jul  3 17:34:21 2017
+++ src/usr.bin/stat/stat.1	Tue Sep 19 17:45:28 2017
@@ -1,4 +1,4 @@
-.\"	$NetBSD: stat.1,v 1.38 2017/07/03 21:34:21 wiz Exp $
+.\"	$NetBSD: stat.1,v 1.39 2017/09/19 21:45:28 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 December 2, 2012
+.Dd September 19, 2017
 .Dt STAT 1
 .Os
 .Sh NAME
@@ -183,7 +183,8 @@ output remains valid.
 Display timestamps using the specified format.
 This format is
 passed directly to
-.Xr strftime 3 .
+.Xr strftime 3 
+with the extension that %f prints nanoseconds if available.
 .It Fl v
 Turn off quiet mode.
 .It Fl x
@@ -274,7 +275,8 @@ applicable, should be in string format.
 May be used in combination with
 .Bl -tag -width Ds
 .It Cm amc
-Display date in strftime(3) format.
+Display date in strftime(3) format
+with the extension that %f prints nanoseconds if available.
 .It Cm dr
 Display actual device name.
 .It Cm gu
Index: src/usr.bin/stat/stat.c
diff -u src/usr.bin/stat/stat.c:1.38 src/usr.bin/stat/stat.c:1.39
--- src/usr.bin/stat/stat.c:1.38	Thu Jan  3 08:28:41 2013
+++ src/usr.bin/stat/stat.c	Tue Sep 19 17:45:28 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: stat.c,v 1.38 2013/01/03 13:28:41 dsl Exp $ */
+/*	$NetBSD: stat.c,v 1.39 2017/09/19 21:45:28 christos Exp $ */
 
 /*
  * Copyright (c) 2002-2011 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 #include 
 #if !defined(lint)
-__RCSID("$NetBSD: stat.c,v 1.38 2013/01/03 13:28:41 dsl Exp $");
+__RCSID("$NetBSD: stat.c,v 1.39 2017/09/19 21:45:28 christos Exp $");
 #endif
 
 #if ! HAVE_NBTOOL_CONFIG_H
@@ -105,12 +105,13 @@ __RCSID("$NetBSD: stat.c,v 1.38 2013/01/
 	"st_blksize=%k st_blocks=%b" SHELL_F
 #define LINUX_FORMAT \
 	"  File: \"%N\"%n" \
-	"  Size: %-11z  FileType: %HT%n" \
-	"  Mode: (%04OLp/%.10Sp) Uid: (%5u/%8Su)  Gid: (%5g/%8Sg)%n" \
+	"  Size: %-11z  Blocks: %-11b  IO Block: %-11k  %HT%n" \
 	"Device: %Hd,%Ld   Inode: %iLinks: %l%n" \
+	"  Mode: (%04OLp/%.10Sp) Uid: (%5u/%8Su)  Gid: (%5g/%8Sg)%n" \
 	"Access: %Sa%n" \
 	"Modify: %Sm%n" \
-	"Change: %Sc"
+	"Change: %Sc%n" \
+	" Birth: %SB"
 
 #define TIME_FORMAT	"%b %e %T %Y"
 
@@ -262,6 +263,7 @@ main(int argc, char *argv[])
 errx(1, "can't use format '%c' with '%c'",
 fmtchar, ch);
 			fmtchar = ch;
+			timefmt = "%Y-%m-%d %H:%M:%S.%f %z";
 			break;
 		case 't':
 			timefmt = optarg;
@@ -561,6 +563,34 @@ output(const struct stat *st, const char
 	(void)fflush(stdout);
 }
 
+static const char *
+fmttime(char *buf, size_t len, const char *fmt, time_t secs, long nsecs)
+{
+	struct tm tm;
+	char *fmt2;
+	if (localtime_r(, ) == NULL) {
+		secs = 0;
+		(void)localtime_r(, );
+	}
+	if ((fmt2 = strstr(fmt, "%f")) != NULL) {
+		size_t flen = strlen(fmt) + 1024;
+		size_t o = (size_t)(fmt2 - fmt);
+		fmt2 = calloc(flen, 1);
+		if (fmt2 != NULL) {
+			memcpy(fmt2, fmt, o);
+			int sl = snprintf(fmt2 + o, flen - o, "%.9ld", nsecs);
+			if (sl == -1)
+sl = 0;
+			strcpy(fmt2 + sl + o, fmt + o + 2);
+			fmt = fmt2;
+		}
+	}
+
+	(void)strftime(buf, len, fmt, );
+	free(fmt2);
+	return buf;
+}
+
 /*
  * Arranges output according to a single parsed format substring.
  */
@@ -572,13 +602,12 @@ format1(const struct stat *st,
 int flags, int size, int prec, int ofmt,
 int hilo, int what, int quiet)
 {
-	u_int64_t data;
+	uint64_t data;
 	char *stmp, lfmt[24], tmp[20];
 	const char *sdata;
 	char smode[12], sid[12], path[PATH_MAX + 4], visbuf[PATH_MAX * 4 + 4];
 	struct passwd *pw;
 	struct group *gr;
-	struct tm *tm;
 	time_t secs;
 	long nsecs;
 	int l;
@@ -629,8 +658,12 @@ format1(const struct stat *st,
 #else /* HAVE_DEVNAME */
 		0;
 #endif /* HAVE_DEVNAME */
-		if (ofmt == 0)
-			ofmt = FMTF_UNSIGNED;
+		if (ofmt == 0) {
+			if (data == (uint64_t)-1)
+ofmt = FMTF_DECIMAL;
+			else
+ofmt = FMTF_UNSIGNED;
+		}
 		break;
 	case SHOW_st_ino:
 		small = (sizeof(st->st_ino) == 4);
@@ -745,12 +778,8 @@ format1(const struct stat *st,
 #endif /* HAVE_STRUCT_STAT_ST_BIRTHTIME */
 		small = (sizeof(secs) == 4);
 		data = secs;
-		tm = localtime();
-		if (tm == NULL) {
-			secs = 0;
-			tm = 

CVS commit: src/usr.bin/stat

2017-09-19 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Sep 19 21:45:28 UTC 2017

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

Log Message:
- if st_dev/st_rdev == NODEV print -1 instead of unsigned
- update to the latest linux stat(1) format for -x (kind of)
- add the ability to display nanoseconds, like linux does
- change u_intX_t -> uintX_t


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/usr.bin/stat/stat.1 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

2013-01-03 Thread David Laight
Module Name:src
Committed By:   dsl
Date:   Thu Jan  3 13:28:41 UTC 2013

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

Log Message:
Unset HAVE_DEVNAME for tools build.
config only checks for the symbol in libc, we need the correct prototype.
Which is excluded even on NetBSD (_NETBSD_SOURCE isn't defined in stdlib.h).


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 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.37 src/usr.bin/stat/stat.c:1.38
--- src/usr.bin/stat/stat.c:1.37	Sun Dec  2 21:13:07 2012
+++ src/usr.bin/stat/stat.c	Thu Jan  3 13:28:41 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: stat.c,v 1.37 2012/12/02 21:13:07 erh Exp $ */
+/*	$NetBSD: stat.c,v 1.38 2013/01/03 13:28:41 dsl Exp $ */
 
 /*
  * Copyright (c) 2002-2011 The NetBSD Foundation, Inc.
@@ -31,11 +31,13 @@
 
 #if HAVE_NBTOOL_CONFIG_H
 #include nbtool_config.h
+/* config checked libc, we need the prototype as well */
+#undef HAVE_DEVNAME
 #endif
 
 #include sys/cdefs.h
 #if !defined(lint)
-__RCSID($NetBSD: stat.c,v 1.37 2012/12/02 21:13:07 erh Exp $);
+__RCSID($NetBSD: stat.c,v 1.38 2013/01/03 13:28:41 dsl Exp $);
 #endif
 
 #if ! HAVE_NBTOOL_CONFIG_H
@@ -607,9 +609,9 @@ format1(const struct stat *st,
 		sdata = (what == SHOW_st_dev) ?
 		devname(st-st_dev, S_IFBLK) :
 		devname(st-st_rdev, 
-		S_ISCHR(st-st_mode) ? S_IFCHR :
-		S_ISBLK(st-st_mode) ? S_IFBLK :
-		0U);
+			S_ISCHR(st-st_mode) ? S_IFCHR :
+			S_ISBLK(st-st_mode) ? S_IFBLK :
+			0U);
 		if (sdata == NULL)
 			sdata = ???;
 #endif /* HAVE_DEVNAME */



CVS commit: src/usr.bin/stat

2013-01-03 Thread David Laight
Module Name:src
Committed By:   dsl
Date:   Thu Jan  3 13:28:41 UTC 2013

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

Log Message:
Unset HAVE_DEVNAME for tools build.
config only checks for the symbol in libc, we need the correct prototype.
Which is excluded even on NetBSD (_NETBSD_SOURCE isn't defined in stdlib.h).


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 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

2012-12-02 Thread Eric Haszlakiewicz
Module Name:src
Committed By:   erh
Date:   Sun Dec  2 21:13:07 UTC 2012

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

Log Message:
Honor the -t option to set the time format when running stat -s.
Document the format used by -s on the man page.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/usr.bin/stat/stat.1
cvs rdiff -u -r1.36 -r1.37 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.34 src/usr.bin/stat/stat.1:1.35
--- src/usr.bin/stat/stat.1:1.34	Thu Sep 22 20:23:55 2011
+++ src/usr.bin/stat/stat.1	Sun Dec  2 21:13:07 2012
@@ -1,4 +1,4 @@
-.\	$NetBSD: stat.1,v 1.34 2011/09/22 20:23:55 apb Exp $
+.\	$NetBSD: stat.1,v 1.35 2012/12/02 21:13:07 erh Exp $
 .\
 .\ Copyright (c) 2002-2011 The NetBSD Foundation, Inc.
 .\ All rights reserved.
@@ -168,6 +168,17 @@ 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
+stat -t %s -f $FMT .
+.Ed
+Note that if you use a timeformat that contains embedded whitespace or shell 
+meta-characters you will need to include appropriate quoting so the
+.Fl s
+output remains valid.
 .It Fl t Ar timefmt
 Display timestamps using the specified format.
 This format is

Index: src/usr.bin/stat/stat.c
diff -u src/usr.bin/stat/stat.c:1.36 src/usr.bin/stat/stat.c:1.37
--- src/usr.bin/stat/stat.c:1.36	Thu Sep 22 20:23:56 2011
+++ src/usr.bin/stat/stat.c	Sun Dec  2 21:13:07 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: stat.c,v 1.36 2011/09/22 20:23:56 apb Exp $ */
+/*	$NetBSD: stat.c,v 1.37 2012/12/02 21:13:07 erh Exp $ */
 
 /*
  * Copyright (c) 2002-2011 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include sys/cdefs.h
 #if !defined(lint)
-__RCSID($NetBSD: stat.c,v 1.36 2011/09/22 20:23:56 apb Exp $);
+__RCSID($NetBSD: stat.c,v 1.37 2012/12/02 21:13:07 erh Exp $);
 #endif
 
 #if ! HAVE_NBTOOL_CONFIG_H
@@ -76,7 +76,7 @@ __RCSID($NetBSD: stat.c,v 1.36 2011/09/
 #if HAVE_STRUCT_STAT_ST_BIRTHTIME
 #define DEF_B \%SB\ 
 #define RAW_B %B 
-#define SHELL_B st_birthtime=%B 
+#define SHELL_B st_birthtime=%SB 
 #else /* HAVE_STRUCT_STAT_ST_BIRTHTIME */
 #define DEF_B
 #define RAW_B
@@ -99,7 +99,7 @@ __RCSID($NetBSD: stat.c,v 1.36 2011/09/
 #define SHELL_FORMAT \
 	st_dev=%d st_ino=%i st_mode=%#p st_nlink=%l  \
 	st_uid=%u st_gid=%g st_rdev=%r st_size=%z  \
-	st_atime=%a st_mtime=%m st_ctime=%c  SHELL_B \
+	st_atime=%Sa st_mtime=%Sm st_ctime=%Sc  SHELL_B \
 	st_blksize=%k st_blocks=%b SHELL_F
 #define LINUX_FORMAT \
 	  File: \%N\%n \
@@ -299,6 +299,8 @@ main(int argc, char *argv[])
 		break;
 	case 's':
 		statfmt = SHELL_FORMAT;
+		if (timefmt == NULL)
+			timefmt = %s;
 		break;
 	case 'x':
 		statfmt = LINUX_FORMAT;



CVS commit: src/usr.bin/stat

2012-12-02 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Mon Dec  3 07:49:21 UTC 2012

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

Log Message:
Bump date for previous. Remove trailing whitespace.


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 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.35 src/usr.bin/stat/stat.1:1.36
--- src/usr.bin/stat/stat.1:1.35	Sun Dec  2 21:13:07 2012
+++ src/usr.bin/stat/stat.1	Mon Dec  3 07:49:21 2012
@@ -1,4 +1,4 @@
-.\	$NetBSD: stat.1,v 1.35 2012/12/02 21:13:07 erh Exp $
+.\	$NetBSD: stat.1,v 1.36 2012/12/03 07:49:21 wiz 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 September 22, 2011
+.Dd December 2, 2012
 .Dt STAT 1
 .Os
 .Sh NAME
@@ -168,14 +168,14 @@ suitable for initializing variables.
 When run as
 .Nm readlink ,
 suppress error messages.
-This is equivalent to specifying 
-.Bd -literal 
+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
 stat -t %s -f $FMT .
 .Ed
-Note that if you use a timeformat that contains embedded whitespace or shell 
+Note that if you use a timeformat that contains embedded whitespace or shell
 meta-characters you will need to include appropriate quoting so the
 .Fl s
 output remains valid.



CVS commit: src/usr.bin/stat

2012-12-02 Thread Eric Haszlakiewicz
Module Name:src
Committed By:   erh
Date:   Sun Dec  2 21:13:07 UTC 2012

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

Log Message:
Honor the -t option to set the time format when running stat -s.
Document the format used by -s on the man page.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/usr.bin/stat/stat.1
cvs rdiff -u -r1.36 -r1.37 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

2012-12-02 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Mon Dec  3 07:49:21 UTC 2012

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

Log Message:
Bump date for previous. Remove trailing whitespace.


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 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

2011-09-22 Thread Alan Barrett
Module Name:src
Committed By:   apb
Date:   Thu Sep 22 20:23:56 UTC 2011

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

Log Message:
Use vis(3) encoding when a string format is modified by the '#' flag.
Also bump copyright years.


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/usr.bin/stat/stat.1
cvs rdiff -u -r1.35 -r1.36 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.33 src/usr.bin/stat/stat.1:1.34
--- src/usr.bin/stat/stat.1:1.33	Fri Sep 16 14:32:53 2011
+++ src/usr.bin/stat/stat.1	Thu Sep 22 20:23:55 2011
@@ -1,6 +1,6 @@
-.\	$NetBSD: stat.1,v 1.33 2011/09/16 14:32:53 apb Exp $
+.\	$NetBSD: stat.1,v 1.34 2011/09/22 20:23:55 apb Exp $
 .\
-.\ Copyright (c) 2002-2005 The NetBSD Foundation, Inc.
+.\ Copyright (c) 2002-2011 The NetBSD Foundation, Inc.
 .\ All rights reserved.
 .\
 .\ This code is derived from software contributed to The NetBSD Foundation
@@ -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 September 16, 2011
+.Dd September 22, 2011
 .Dt STAT 1
 .Os
 .Sh NAME
@@ -202,9 +202,12 @@
 Any of the following optional flags:
 .Bl -tag -width Ds
 .It Cm #
-Selects an alternate output form for octal and hexadecimal output.
-Non-zero octal output will have a leading zero, and non-zero
-hexadecimal output will have
+Selects an alternate output form for string, octal and hexadecimal output.
+String output will be encoded in
+.Xr vis 3
+style.
+Non-zero octal output will have a leading zero.
+Non-zero hexadecimal output will have
 .Dq 0x
 prepended to it.
 .It Cm +
@@ -582,6 +585,18 @@
 Apr 25 10:36:34 2002 /tmp/bar
 Apr 24 16:47:35 2002 /tmp/foo
 .Ed
+.Pp
+User names, group names, and file names that contain spaces
+or other special characters may be encoded in
+.Xr vis 3
+style, using the
+.Cm \#
+modifier:
+.Bd -literal -offset indent
+\*[Gt] ln -s 'target with spaces' 'link with spaces'
+\*[Gt] stat -f %#N%#SY 'link with spaces'
+link\eswith\esspaces -\*[Gt] target\eswith\esspaces
+.Ed
 .Sh SEE ALSO
 .Xr basename 1 ,
 .Xr dirname 1 ,

Index: src/usr.bin/stat/stat.c
diff -u src/usr.bin/stat/stat.c:1.35 src/usr.bin/stat/stat.c:1.36
--- src/usr.bin/stat/stat.c:1.35	Tue Sep  6 18:31:22 2011
+++ src/usr.bin/stat/stat.c	Thu Sep 22 20:23:56 2011
@@ -1,7 +1,7 @@
-/*	$NetBSD: stat.c,v 1.35 2011/09/06 18:31:22 joerg Exp $ */
+/*	$NetBSD: stat.c,v 1.36 2011/09/22 20:23:56 apb Exp $ */
 
 /*
- * Copyright (c) 2002 The NetBSD Foundation, Inc.
+ * Copyright (c) 2002-2011 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -35,7 +35,7 @@
 
 #include sys/cdefs.h
 #if !defined(lint)
-__RCSID($NetBSD: stat.c,v 1.35 2011/09/06 18:31:22 joerg Exp $);
+__RCSID($NetBSD: stat.c,v 1.36 2011/09/22 20:23:56 apb Exp $);
 #endif
 
 #if ! HAVE_NBTOOL_CONFIG_H
@@ -61,6 +61,7 @@
 #include string.h
 #include time.h
 #include unistd.h
+#include vis.h
 
 #if HAVE_STRUCT_STAT_ST_FLAGS
 #define DEF_F %#Xf 
@@ -365,7 +366,12 @@
 const char *statfmt, int fn, int nonl, int quiet)
 {
 	int flags, size, prec, ofmt, hilo, what;
-	char buf[PATH_MAX + 4 + 1];
+	/*
+	 * buf size is enough for an item of length PATH_MAX,
+	 * multiplied by 4 for vis encoding, plus 4 for symlink
+	 *  -  prefix, plus 1 for \0 terminator.
+	 */
+	char buf[PATH_MAX * 4 + 4 + 1];
 	const char *subfmt;
 	int nl, t, i;
 
@@ -436,6 +442,7 @@
 		 * the leading  -  if STRING is explicitly specified.  The
 		 * sizerdev datum will generate rdev output for character or
 		 * block devices, and size output for all others.
+		 * For STRING output, the # format requests vis encoding.
 		 */
 		flags = 0;
 		do {
@@ -564,13 +571,18 @@
 	u_int64_t data;
 	char *stmp, lfmt[24], tmp[20];
 	const char *sdata;
-	char smode[12], sid[12], path[PATH_MAX + 4];
+	char smode[12], sid[12], path[PATH_MAX + 4], visbuf[PATH_MAX * 4 + 4];
 	struct passwd *pw;
 	struct group *gr;
 	struct tm *tm;
 	time_t secs;
 	long nsecs;
-	int l, small, formats, gottime, shift;
+	int l;
+	int formats;	/* bitmap of allowed formats for this datum */
+	int small;	/* true if datum is a small integer */
+	int gottime;	/* true if secs and nsecs are valid */
+	int shift;	/* powers of 2 to scale numbers before printing */
+	size_t prefixlen; /* length of constant prefix for string data */
 
 	formats = 0;
 	small = 0;
@@ -578,6 +590,7 @@
 	secs = 0;
 	nsecs = 0;
 	shift = 0;
+	prefixlen = 0;
 
 	/*
 	 * First, pick out the data and tweak it based on hilo or
@@ -814,6 +827,7 @@
 path[0] = '\0';
 			}
 			sdata = path + (ofmt == FMTF_STRING ? 0 : 4);
+			prefixlen = (ofmt == FMTF_STRING ? 4 : 0);
 		}
 
 		formats = FMTF_STRING;
@@ -835,6 +849,7 @@
 			}
 			path[l + 4] = '\0';
 			sdata = path + (ofmt == FMTF_STRING ? 0 : 4);
+			

CVS commit: src/usr.bin/stat

2011-09-22 Thread Alan Barrett
Module Name:src
Committed By:   apb
Date:   Thu Sep 22 20:23:56 UTC 2011

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

Log Message:
Use vis(3) encoding when a string format is modified by the '#' flag.
Also bump copyright years.


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/usr.bin/stat/stat.1
cvs rdiff -u -r1.35 -r1.36 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

2011-09-16 Thread Alan Barrett
Module Name:src
Committed By:   apb
Date:   Fri Sep 16 11:06:27 UTC 2011

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

Log Message:
Anothe difference in output format: stat -f %Z does not add any
space in major,minor for device nodes, whereas both ls -l and
find -ls add at least one space.


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 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.30 src/usr.bin/stat/stat.1:1.31
--- src/usr.bin/stat/stat.1:1.30	Thu Sep 15 19:56:35 2011
+++ src/usr.bin/stat/stat.1	Fri Sep 16 11:06:27 2011
@@ -1,4 +1,4 @@
-.\	$NetBSD: stat.1,v 1.30 2011/09/15 19:56:35 apb Exp $
+.\	$NetBSD: stat.1,v 1.31 2011/09/16 11:06:27 apb Exp $
 .\
 .\ Copyright (c) 2002-2005 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 September 15, 2011
+.Dd September 16, 2011
 .Dt STAT 1
 .Os
 .Sh NAME
@@ -435,7 +435,7 @@
 The target of a symbolic link.
 .It Cm Z
 Expands to
-.Dq major,minor
+.Dq Ar major Ns , Ns Ar minor
 from the rdev field for character or block
 special devices and gives size output for all others.
 .El
@@ -477,7 +477,11 @@
 .Ic find ... -ls
 (except that
 .Xr find 1
-displays the time in a different format):
+displays the time in a different format, and
+.Xr find 1
+adds at least one space after the comma in
+.Dq Ar major Ns , Ns Ar minor
+for device nodes):
 .Bd -literal -offset indent
 \*[Gt] stat -f %7i %6b %-11Sp %3l %-17Su %-17Sg %9Z %Sm %N%SY /tmp/bar
   78852  0 -rw-r--r--1 root  wheel 0 Jul  8 10:26:03 2004 /tmp/bar
@@ -490,7 +494,12 @@
 .Ic ls -lTd
 (except that
 .Xr ls 1
-adjusts the column spacing differently when listing multiple files):
+adjusts the column spacing differently when listing multiple files,
+and
+.Xr ls 1
+adds at least one space after the comma in
+.Dq Ar major Ns , Ns Ar minor
+for device nodes):
 .Bd -literal -offset indent
 \*[Gt] stat -f %-11Sp %l %Su  %Sg  %5Z %Sm %N%SY /tmp/bar
 -rw-r--r--  1 root  wheel  0 Jul  8 10:26:03 2004 /tmp/bar



CVS commit: src/usr.bin/stat

2011-09-16 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Fri Sep 16 13:33:13 UTC 2011

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

Log Message:
Remove unnecessary Ns.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 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.31 src/usr.bin/stat/stat.1:1.32
--- src/usr.bin/stat/stat.1:1.31	Fri Sep 16 11:06:27 2011
+++ src/usr.bin/stat/stat.1	Fri Sep 16 13:33:13 2011
@@ -1,4 +1,4 @@
-.\	$NetBSD: stat.1,v 1.31 2011/09/16 11:06:27 apb Exp $
+.\	$NetBSD: stat.1,v 1.32 2011/09/16 13:33:13 wiz Exp $
 .\
 .\ Copyright (c) 2002-2005 The NetBSD Foundation, Inc.
 .\ All rights reserved.
@@ -435,7 +435,7 @@
 The target of a symbolic link.
 .It Cm Z
 Expands to
-.Dq Ar major Ns , Ns Ar minor
+.Dq Ar major , Ns Ar minor
 from the rdev field for character or block
 special devices and gives size output for all others.
 .El
@@ -480,7 +480,7 @@
 displays the time in a different format, and
 .Xr find 1
 adds at least one space after the comma in
-.Dq Ar major Ns , Ns Ar minor
+.Dq Ar major , Ns Ar minor
 for device nodes):
 .Bd -literal -offset indent
 \*[Gt] stat -f %7i %6b %-11Sp %3l %-17Su %-17Sg %9Z %Sm %N%SY /tmp/bar
@@ -498,7 +498,7 @@
 and
 .Xr ls 1
 adds at least one space after the comma in
-.Dq Ar major Ns , Ns Ar minor
+.Dq Ar major , Ns Ar minor
 for device nodes):
 .Bd -literal -offset indent
 \*[Gt] stat -f %-11Sp %l %Su  %Sg  %5Z %Sm %N%SY /tmp/bar



CVS commit: src/usr.bin/stat

2011-09-16 Thread Alan Barrett
Module Name:src
Committed By:   apb
Date:   Fri Sep 16 14:32:53 UTC 2011

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

Log Message:
More corrections to format compatibility between stat(1), find(1) -ls,
and ls(1) -lT.


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 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.32 src/usr.bin/stat/stat.1:1.33
--- src/usr.bin/stat/stat.1:1.32	Fri Sep 16 13:33:13 2011
+++ src/usr.bin/stat/stat.1	Fri Sep 16 14:32:53 2011
@@ -1,4 +1,4 @@
-.\	$NetBSD: stat.1,v 1.32 2011/09/16 13:33:13 wiz Exp $
+.\	$NetBSD: stat.1,v 1.33 2011/09/16 14:32:53 apb Exp $
 .\
 .\ Copyright (c) 2002-2005 The NetBSD Foundation, Inc.
 .\ All rights reserved.
@@ -479,7 +479,7 @@
 .Xr find 1
 displays the time in a different format, and
 .Xr find 1
-adds at least one space after the comma in
+sometimes adds one or more spaces after the comma in
 .Dq Ar major , Ns Ar minor
 for device nodes):
 .Bd -literal -offset indent
@@ -501,7 +501,7 @@
 .Dq Ar major , Ns Ar minor
 for device nodes):
 .Bd -literal -offset indent
-\*[Gt] stat -f %-11Sp %l %Su  %Sg  %5Z %Sm %N%SY /tmp/bar
+\*[Gt] stat -f %-11Sp %l %Su  %Sg  %Z %Sm %N%SY /tmp/bar
 -rw-r--r--  1 root  wheel  0 Jul  8 10:26:03 2004 /tmp/bar
 
 \*[Gt] ls -lTd /tmp/bar



CVS commit: src/usr.bin/stat

2011-09-16 Thread Alan Barrett
Module Name:src
Committed By:   apb
Date:   Fri Sep 16 11:06:27 UTC 2011

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

Log Message:
Anothe difference in output format: stat -f %Z does not add any
space in major,minor for device nodes, whereas both ls -l and
find -ls add at least one space.


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 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

2011-09-16 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Fri Sep 16 13:33:13 UTC 2011

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

Log Message:
Remove unnecessary Ns.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 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

2011-09-16 Thread Alan Barrett
Module Name:src
Committed By:   apb
Date:   Fri Sep 16 14:32:53 UTC 2011

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

Log Message:
More corrections to format compatibility between stat(1), find(1) -ls,
and ls(1) -lT.


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 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

2011-09-15 Thread Alan Barrett
Module Name:src
Committed By:   apb
Date:   Thu Sep 15 19:56:35 UTC 2011

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

Log Message:
Add examples of formats for stat(1) to simulate find -ls and ls -lTd.


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 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.29 src/usr.bin/stat/stat.1:1.30
--- src/usr.bin/stat/stat.1:1.29	Wed Feb 16 23:08:29 2011
+++ src/usr.bin/stat/stat.1	Thu Sep 15 19:56:35 2011
@@ -1,4 +1,4 @@
-.\	$NetBSD: stat.1,v 1.29 2011/02/16 23:08:29 christos Exp $
+.\	$NetBSD: stat.1,v 1.30 2011/09/15 19:56:35 apb Exp $
 .\
 .\ Copyright (c) 2002-2005 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 February 16, 2011
+.Dd September 15, 2011
 .Dt STAT 1
 .Os
 .Sh NAME
@@ -473,6 +473,32 @@
 0 78852 -rw-r--r-- 1 root wheel 0 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
 .Pp
+This example produces output very similar to that from
+.Ic find ... -ls
+(except that
+.Xr find 1
+displays the time in a different format):
+.Bd -literal -offset indent
+\*[Gt] stat -f %7i %6b %-11Sp %3l %-17Su %-17Sg %9Z %Sm %N%SY /tmp/bar
+  78852  0 -rw-r--r--1 root  wheel 0 Jul  8 10:26:03 2004 /tmp/bar
+
+\*[Gt] find /tmp/bar -ls -exit
+  78852  0 -rw-r--r--1 root  wheel 0 Jul  8  2004 /tmp/bar
+.Ed
+.Pp
+This example produces output very similar to that from
+.Ic ls -lTd
+(except that
+.Xr ls 1
+adjusts the column spacing differently when listing multiple files):
+.Bd -literal -offset indent
+\*[Gt] stat -f %-11Sp %l %Su  %Sg  %5Z %Sm %N%SY /tmp/bar
+-rw-r--r--  1 root  wheel  0 Jul  8 10:26:03 2004 /tmp/bar
+
+\*[Gt] ls -lTd /tmp/bar
+-rw-r--r--  1 root  wheel  0 Jul  8 10:26:03 2004 /tmp/bar
+.Ed
+.Pp
 Given a symbolic link
 .Dq foo
 that points from



CVS commit: src/usr.bin/stat

2011-09-15 Thread Alan Barrett
Module Name:src
Committed By:   apb
Date:   Thu Sep 15 19:56:35 UTC 2011

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

Log Message:
Add examples of formats for stat(1) to simulate find -ls and ls -lTd.


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 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

2011-09-06 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Tue Sep  6 18:31:22 UTC 2011

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

Log Message:
static + __dead


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 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.34 src/usr.bin/stat/stat.c:1.35
--- src/usr.bin/stat/stat.c:1.34	Wed Feb 16 23:08:29 2011
+++ src/usr.bin/stat/stat.c	Tue Sep  6 18:31:22 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: stat.c,v 1.34 2011/02/16 23:08:29 christos Exp $ */
+/*	$NetBSD: stat.c,v 1.35 2011/09/06 18:31:22 joerg Exp $ */
 
 /*
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include sys/cdefs.h
 #if !defined(lint)
-__RCSID($NetBSD: stat.c,v 1.34 2011/02/16 23:08:29 christos Exp $);
+__RCSID($NetBSD: stat.c,v 1.35 2011/09/06 18:31:22 joerg Exp $);
 #endif
 
 #if ! HAVE_NBTOOL_CONFIG_H
@@ -174,18 +174,18 @@
 #define SHOW_filename	'N'
 #define SHOW_sizerdev	'Z'
 
-void	usage(const char *);
-void	output(const struct stat *, const char *,
+static void	usage(const char *) __dead;
+static void	output(const struct stat *, const char *,
 	const char *, int, int, int);
-int	format1(const struct stat *,	/* stat info */
+static int	format1(const struct stat *,	/* stat info */
 	const char *,		/* the file name */
 	const char *, int,		/* the format string itself */
 	char *, size_t,		/* a place to put the output */
 	int, int, int, int,		/* the parsed format */
 	int, int, int);
 
-const char *timefmt;
-int linkfail;
+static const char *timefmt;
+static int linkfail;
 
 #define addchar(s, c, nl) \
 	do { \
@@ -349,7 +349,7 @@
 	return (am_readlink ? linkfail : errs);
 }
 
-void
+static void
 usage(const char *synopsis)
 {
 
@@ -360,7 +360,7 @@
 /* 
  * Parses a format string.
  */
-void
+static void
 output(const struct stat *st, const char *file,
 const char *statfmt, int fn, int nonl, int quiet)
 {
@@ -553,7 +553,7 @@
 /*
  * Arranges output according to a single parsed format substring.
  */
-int
+static int
 format1(const struct stat *st,
 const char *file,
 const char *fmt, int flen,



CVS commit: src/usr.bin/stat

2011-09-06 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Tue Sep  6 18:31:22 UTC 2011

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

Log Message:
static + __dead


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 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

2011-08-17 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Aug 17 13:22:33 UTC 2011

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

Log Message:
document non-literal format strings


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/stat/Makefile

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.7 src/usr.bin/stat/Makefile:1.8
--- src/usr.bin/stat/Makefile:1.7	Thu Jul 24 23:21:17 2003
+++ src/usr.bin/stat/Makefile	Wed Aug 17 09:22:33 2011
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.7 2003/07/25 03:21:17 atatat Exp $
+#	$NetBSD: Makefile,v 1.8 2011/08/17 13:22:33 christos Exp $
 
 PROG=	stat
 
@@ -7,4 +7,6 @@
 MLINKS=	stat.1 readlink.1
 .endif
 
+COPTS.stat.c += -Wno-format-nonliteral
+
 .include bsd.prog.mk



CVS commit: src/usr.bin/stat

2011-08-17 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Aug 17 13:22:33 UTC 2011

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

Log Message:
document non-literal format strings


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/stat/Makefile

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

2011-02-16 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Feb 16 23:08:29 UTC 2011

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

Log Message:
Add verbose mode for readlink.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/usr.bin/stat/stat.1
cvs rdiff -u -r1.33 -r1.34 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.28 src/usr.bin/stat/stat.1:1.29
--- src/usr.bin/stat/stat.1:1.28	Mon Apr  5 17:25:01 2010
+++ src/usr.bin/stat/stat.1	Wed Feb 16 18:08:29 2011
@@ -1,4 +1,4 @@
-.\	$NetBSD: stat.1,v 1.28 2010/04/05 21:25:01 joerg Exp $
+.\	$NetBSD: stat.1,v 1.29 2011/02/16 23:08:29 christos Exp $
 .\
 .\ Copyright (c) 2002-2005 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 November 7, 2008
+.Dd February 16, 2011
 .Dt STAT 1
 .Os
 .Sh NAME
@@ -47,7 +47,7 @@
 .Op Fl t Ar timefmt
 .Op Ar
 .Nm readlink
-.Op Fl fn
+.Op Fl fnqsv
 .Op Ar
 .Sh DESCRIPTION
 The
@@ -165,11 +165,16 @@
 Display information in
 .Dq shell output ,
 suitable for initializing variables.
+When run as
+.Nm readlink ,
+suppress error messages.
 .It Fl t Ar timefmt
 Display timestamps using the specified format.
 This format is
 passed directly to
 .Xr strftime 3 .
+.It Fl v
+Turn off quiet mode.
 .It Fl x
 Display information in a more verbose way as known from some Linux
 distributions.

Index: src/usr.bin/stat/stat.c
diff -u src/usr.bin/stat/stat.c:1.33 src/usr.bin/stat/stat.c:1.34
--- src/usr.bin/stat/stat.c:1.33	Sat Jan 15 17:54:10 2011
+++ src/usr.bin/stat/stat.c	Wed Feb 16 18:08:29 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: stat.c,v 1.33 2011/01/15 22:54:10 njoly Exp $ */
+/*	$NetBSD: stat.c,v 1.34 2011/02/16 23:08:29 christos Exp $ */
 
 /*
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include sys/cdefs.h
 #if !defined(lint)
-__RCSID($NetBSD: stat.c,v 1.33 2011/01/15 22:54:10 njoly Exp $);
+__RCSID($NetBSD: stat.c,v 1.34 2011/02/16 23:08:29 christos Exp $);
 #endif
 
 #if ! HAVE_NBTOOL_CONFIG_H
@@ -176,13 +176,13 @@
 
 void	usage(const char *);
 void	output(const struct stat *, const char *,
-	const char *, int, int);
+	const char *, int, int, int);
 int	format1(const struct stat *,	/* stat info */
 	const char *,		/* the file name */
 	const char *, int,		/* the format string itself */
 	char *, size_t,		/* a place to put the output */
 	int, int, int, int,		/* the parsed format */
-	int, int);
+	int, int, int);
 
 const char *timefmt;
 int linkfail;
@@ -211,10 +211,12 @@
 	statfmt = NULL;
 	timefmt = NULL;
 
+	setprogname(argv[0]);
+
 	if (strcmp(getprogname(), readlink) == 0) {
 		am_readlink = 1;
-		options = fn;
-		synopsis = [-fn] [file ...];
+		options = fnqsv;
+		synopsis = [-fnqsv] [file ...];
 		statfmt = %Y;
 		fmtchar = 'f';
 		quiet = 1;
@@ -247,6 +249,11 @@
 		case 'l':
 		case 'r':
 		case 's':
+			if (am_readlink) {
+quiet = 1;
+break;
+			}
+			/*FALLTHROUGH*/
 		case 'x':
 			if (fmtchar != 0)
 errx(1, can't use format '%c' with '%c',
@@ -256,6 +263,9 @@
 		case 't':
 			timefmt = optarg;
 			break;
+		case 'v':
+			quiet = 0;
+			break;
 		default:
 			usage(synopsis);
 		}
@@ -329,7 +339,7 @@
 usestat ? stat : lstat);
 		}
 		else
-			output(st, argv[0], statfmt, fn, nonl);
+			output(st, argv[0], statfmt, fn, nonl, quiet);
 
 		argv++;
 		argc--;
@@ -352,7 +362,7 @@
  */
 void
 output(const struct stat *st, const char *file,
-const char *statfmt, int fn, int nonl)
+const char *statfmt, int fn, int nonl, int quiet)
 {
 	int flags, size, prec, ofmt, hilo, what;
 	char buf[PATH_MAX + 4 + 1];
@@ -523,7 +533,7 @@
 		 file,
 		 subfmt, statfmt - subfmt,
 		 buf, sizeof(buf),
-		 flags, size, prec, ofmt, hilo, what);
+		 flags, size, prec, ofmt, hilo, what, quiet);
 
 		for (i = 0; i  t  i  (int)(sizeof(buf) - 1); i++)
 			addchar(stdout, buf[i], nl);
@@ -549,7 +559,7 @@
 const char *fmt, int flen,
 char *buf, size_t blen,
 int flags, int size, int prec, int ofmt,
-int hilo, int what)
+int hilo, int what, int quiet)
 {
 	u_int64_t data;
 	char *stmp, lfmt[24], tmp[20];
@@ -797,6 +807,8 @@
 		} else {
 			snprintf(path, sizeof(path),  - );
 			if (realpath(file, path + 4) == NULL) {
+if (!quiet)
+	warn(realpath `%s', file);
 linkfail = 1;
 l = 0;
 path[0] = '\0';
@@ -815,6 +827,8 @@
 			snprintf(path, sizeof(path),  - );
 			l = readlink(file, path + 4, sizeof(path) - 4 - 1);
 			if (l == -1) {
+if (!quiet)
+	warn(readlink `%s', file);
 linkfail = 1;
 l = 0;
 path[0] = '\0';
@@ -933,13 +947,13 @@
 			fmt, flen,
 			majdev, sizeof(majdev),
 			flags, size, prec,
-			ofmt, HIGH_PIECE, SHOW_st_rdev);
+			

CVS commit: src/usr.bin/stat

2011-02-16 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Feb 16 23:08:29 UTC 2011

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

Log Message:
Add verbose mode for readlink.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/usr.bin/stat/stat.1
cvs rdiff -u -r1.33 -r1.34 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

2011-01-15 Thread Nicolas Joly
Module Name:src
Committed By:   njoly
Date:   Sat Jan 15 22:54:11 UTC 2011

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

Log Message:
Do not crash if a date cannot be represented (localtime returning
NULL), use the Epoch value instead.


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 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.32 src/usr.bin/stat/stat.c:1.33
--- src/usr.bin/stat/stat.c:1.32	Thu Dec 16 05:42:14 2010
+++ src/usr.bin/stat/stat.c	Sat Jan 15 22:54:10 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: stat.c,v 1.32 2010/12/16 05:42:14 dholland Exp $ */
+/*	$NetBSD: stat.c,v 1.33 2011/01/15 22:54:10 njoly Exp $ */
 
 /*
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include sys/cdefs.h
 #if !defined(lint)
-__RCSID($NetBSD: stat.c,v 1.32 2010/12/16 05:42:14 dholland Exp $);
+__RCSID($NetBSD: stat.c,v 1.33 2011/01/15 22:54:10 njoly Exp $);
 #endif
 
 #if ! HAVE_NBTOOL_CONFIG_H
@@ -719,6 +719,10 @@
 		small = (sizeof(secs) == 4);
 		data = secs;
 		tm = localtime(secs);
+		if (tm == NULL) {
+			secs = 0;
+			tm = localtime(secs);
+		}
 		(void)strftime(path, sizeof(path), timefmt, tm);
 		sdata = path;
 		formats = FMTF_DECIMAL | FMTF_OCTAL | FMTF_UNSIGNED | FMTF_HEX |



CVS commit: src/usr.bin/stat

2011-01-15 Thread Nicolas Joly
Module Name:src
Committed By:   njoly
Date:   Sat Jan 15 22:54:11 UTC 2011

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

Log Message:
Do not crash if a date cannot be represented (localtime returning
NULL), use the Epoch value instead.


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 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

2010-12-15 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Thu Dec 16 05:30:16 UTC 2010

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

Log Message:
Use strlcpy, not strncpy, when the desired semantics are strlcpy's
rather than strncpy's.


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 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.30 src/usr.bin/stat/stat.c:1.31
--- src/usr.bin/stat/stat.c:1.30	Thu Nov 25 04:33:30 2010
+++ src/usr.bin/stat/stat.c	Thu Dec 16 05:30:16 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: stat.c,v 1.30 2010/11/25 04:33:30 dholland Exp $ */
+/*	$NetBSD: stat.c,v 1.31 2010/12/16 05:30:16 dholland Exp $ */
 
 /*
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include sys/cdefs.h
 #if !defined(lint)
-__RCSID($NetBSD: stat.c,v 1.30 2010/11/25 04:33:30 dholland Exp $);
+__RCSID($NetBSD: stat.c,v 1.31 2010/12/16 05:30:16 dholland Exp $);
 #endif
 
 #if ! HAVE_NBTOOL_CONFIG_H
@@ -788,7 +788,7 @@
 		small = 0;
 		data = 0;
 		if (file == NULL) {
-			(void)strncpy(path, (stdin), sizeof(path));
+			(void)strlcpy(path, (stdin), sizeof(path));
 			sdata = path;
 		} else {
 			snprintf(path, sizeof(path),  - );
@@ -881,15 +881,15 @@
 		small = 0;
 		data = 0;
 		if (file == NULL) {
-			(void)strncpy(path, (stdin), sizeof(path));
+			(void)strlcpy(path, (stdin), sizeof(path));
 			if (hilo == HIGH_PIECE || hilo == LOW_PIECE)
 hilo = 0;
 		}
 		else if (hilo == 0)
-			(void)strncpy(path, file, sizeof(path));
+			(void)strlcpy(path, file, sizeof(path));
 		else {
 			char *s;
-			(void)strncpy(path, file, sizeof(path));
+			(void)strlcpy(path, file, sizeof(path));
 			s = strrchr(path, '/');
 			if (s != NULL) {
 /* trim off trailing /'s */
@@ -900,7 +900,7 @@
 			}
 			if (hilo == HIGH_PIECE) {
 if (s == NULL)
-	(void)strncpy(path, ., sizeof(path));
+	(void)strlcpy(path, ., sizeof(path));
 else {
 	while (s != path  s[0] == '/')
 		*s-- = '\0';
@@ -909,7 +909,7 @@
 			}
 			else if (hilo == LOW_PIECE) {
 if (s != NULL  s[1] != '\0')
-	(void)strncpy(path, s + 1,
+	(void)strlcpy(path, s + 1,
 		  sizeof(path));
 hilo = 0;
 			}



CVS commit: src/usr.bin/stat

2010-12-15 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Thu Dec 16 05:42:15 UTC 2010

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

Log Message:
Don't pass unused argument. From Doug Barton.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 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.31 src/usr.bin/stat/stat.c:1.32
--- src/usr.bin/stat/stat.c:1.31	Thu Dec 16 05:30:16 2010
+++ src/usr.bin/stat/stat.c	Thu Dec 16 05:42:14 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: stat.c,v 1.31 2010/12/16 05:30:16 dholland Exp $ */
+/*	$NetBSD: stat.c,v 1.32 2010/12/16 05:42:14 dholland Exp $ */
 
 /*
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include sys/cdefs.h
 #if !defined(lint)
-__RCSID($NetBSD: stat.c,v 1.31 2010/12/16 05:30:16 dholland Exp $);
+__RCSID($NetBSD: stat.c,v 1.32 2010/12/16 05:42:14 dholland Exp $);
 #endif
 
 #if ! HAVE_NBTOOL_CONFIG_H
@@ -176,7 +176,7 @@
 
 void	usage(const char *);
 void	output(const struct stat *, const char *,
-	const char *, int, int, int);
+	const char *, int, int);
 int	format1(const struct stat *,	/* stat info */
 	const char *,		/* the file name */
 	const char *, int,		/* the format string itself */
@@ -329,7 +329,7 @@
 usestat ? stat : lstat);
 		}
 		else
-			output(st, argv[0], statfmt, fn, nonl, quiet);
+			output(st, argv[0], statfmt, fn, nonl);
 
 		argv++;
 		argc--;
@@ -352,7 +352,7 @@
  */
 void
 output(const struct stat *st, const char *file,
-const char *statfmt, int fn, int nonl, int quiet)
+const char *statfmt, int fn, int nonl)
 {
 	int flags, size, prec, ofmt, hilo, what;
 	char buf[PATH_MAX + 4 + 1];



CVS commit: src/usr.bin/stat

2010-12-15 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Thu Dec 16 05:42:15 UTC 2010

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

Log Message:
Don't pass unused argument. From Doug Barton.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 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


CVS commit: src/usr.bin/stat

2010-11-24 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Wed Nov 24 22:57:54 UTC 2010

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

Log Message:
Don't printf time_t with %d; fixes PR 44128 from yamt. With this change it
successfully prints mtimes after 2038.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 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.28 src/usr.bin/stat/stat.c:1.29
--- src/usr.bin/stat/stat.c:1.28	Mon Apr 13 23:02:36 2009
+++ src/usr.bin/stat/stat.c	Wed Nov 24 22:57:53 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: stat.c,v 1.28 2009/04/13 23:02:36 lukem Exp $ */
+/*	$NetBSD: stat.c,v 1.29 2010/11/24 22:57:53 dholland Exp $ */
 
 /*
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include sys/cdefs.h
 #if !defined(lint)
-__RCSID($NetBSD: stat.c,v 1.28 2009/04/13 23:02:36 lukem Exp $);
+__RCSID($NetBSD: stat.c,v 1.29 2010/11/24 22:57:53 dholland Exp $);
 #endif
 
 #if ! HAVE_NBTOOL_CONFIG_H
@@ -718,7 +718,6 @@
 #endif /* HAVE_STRUCT_STAT_ST_BIRTHTIME */
 		small = (sizeof(secs) == 4);
 		data = secs;
-		small = 1;
 		tm = localtime(secs);
 		(void)strftime(path, sizeof(path), timefmt, tm);
 		sdata = path;
@@ -989,8 +988,9 @@
 (void)snprintf(tmp, sizeof(tmp), %d, size);
 (void)strcat(lfmt, tmp);
 			}
-			(void)strcat(lfmt, d);
-			return (snprintf(buf, blen, lfmt, secs));
+			(void)strcat(lfmt, lld);
+			return (snprintf(buf, blen, lfmt,
+			(long long)secs));
 		}
 
 		/*
@@ -1013,7 +1013,7 @@
 			(void)snprintf(tmp, sizeof(tmp), %d, size);
 			(void)strcat(lfmt, tmp);
 		}
-		(void)strcat(lfmt, d);
+		(void)strcat(lfmt, lld);
 
 		/*
 		 * The stuff after the decimal point always needs zero
@@ -1025,7 +1025,7 @@
 		 * We can print at most nine digits of precision.  The
 		 * rest we will pad on at the end.
 		 */
-		(void)snprintf(tmp, sizeof(tmp), %dd, prec  9 ? 9 : prec);
+		(void)snprintf(tmp, sizeof(tmp), %dld, prec  9 ? 9 : prec);
 		(void)strcat(lfmt, tmp);
 
 		/*
@@ -1039,7 +1039,7 @@
 		 * Use the format, and then tack on any zeroes that
 		 * might be required to make up the requested precision.
 		 */
-		l = snprintf(buf, blen, lfmt, secs, nsecs);
+		l = snprintf(buf, blen, lfmt, (long long)secs, nsecs);
 		for (; prec  9  l  (int)blen; prec--, l++)
 			(void)strcat(buf, 0);
 		return (l);



CVS commit: src/usr.bin/stat

2010-11-24 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Thu Nov 25 04:33:30 UTC 2010

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

Log Message:
Improve previous with comments.


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 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.29 src/usr.bin/stat/stat.c:1.30
--- src/usr.bin/stat/stat.c:1.29	Wed Nov 24 22:57:53 2010
+++ src/usr.bin/stat/stat.c	Thu Nov 25 04:33:30 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: stat.c,v 1.29 2010/11/24 22:57:53 dholland Exp $ */
+/*	$NetBSD: stat.c,v 1.30 2010/11/25 04:33:30 dholland Exp $ */
 
 /*
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include sys/cdefs.h
 #if !defined(lint)
-__RCSID($NetBSD: stat.c,v 1.29 2010/11/24 22:57:53 dholland Exp $);
+__RCSID($NetBSD: stat.c,v 1.30 2010/11/25 04:33:30 dholland Exp $);
 #endif
 
 #if ! HAVE_NBTOOL_CONFIG_H
@@ -1013,6 +1013,7 @@
 			(void)snprintf(tmp, sizeof(tmp), %d, size);
 			(void)strcat(lfmt, tmp);
 		}
+		/* Seconds: time_t cast to long long. */
 		(void)strcat(lfmt, lld);
 
 		/*
@@ -1024,6 +1025,8 @@
 		/*
 		 * We can print at most nine digits of precision.  The
 		 * rest we will pad on at the end.
+		 *
+		 * Nanoseconds: long.
 		 */
 		(void)snprintf(tmp, sizeof(tmp), %dld, prec  9 ? 9 : prec);
 		(void)strcat(lfmt, tmp);



CVS commit: src/usr.bin/stat

2010-11-24 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Wed Nov 24 22:57:54 UTC 2010

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

Log Message:
Don't printf time_t with %d; fixes PR 44128 from yamt. With this change it
successfully prints mtimes after 2038.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 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

2010-11-24 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Thu Nov 25 04:33:30 UTC 2010

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

Log Message:
Improve previous with comments.


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 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

2010-04-05 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Mon Apr  5 21:25:01 UTC 2010

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

Log Message:
\\ - \e


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 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.27 src/usr.bin/stat/stat.1:1.28
--- src/usr.bin/stat/stat.1:1.27	Thu Mar 11 21:37:01 2010
+++ src/usr.bin/stat/stat.1	Mon Apr  5 21:25:01 2010
@@ -1,4 +1,4 @@
-.\	$NetBSD: stat.1,v 1.27 2010/03/11 21:37:01 enami Exp $
+.\	$NetBSD: stat.1,v 1.28 2010/04/05 21:25:01 joerg Exp $
 .\
 .\ Copyright (c) 2002-2005 The NetBSD Foundation, Inc.
 .\ All rights reserved.
@@ -462,7 +462,7 @@
 exits 0 on success, and \*[Gt]0 if an error occurred.
 .Sh EXAMPLES
 If no options are specified, the default format is
-%d %i %Sp %l %Su %Sg %r %z \\%Sa\\ \\%Sm\\ \\%Sc\\ \\%SB\\ %k %b %#Xf %N.
+%d %i %Sp %l %Su %Sg %r %z \e%Sa\e \e%Sm\e \e%Sc\e \e%SB\e %k %b %#Xf %N.
 .Bd -literal -offset indent
 \*[Gt] stat /tmp/bar
 0 78852 -rw-r--r-- 1 root wheel 0 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