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 <bsd.prog.mk>

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 <sys/cdefs.h>
 #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 <string.h>
 #include <time.h>
 #include <unistd.h>
+#if HAVE_STRUCT_STAT_ST_FLAGS
+#include <util.h>
+#endif
 #include <vis.h>
 
 #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;

Reply via email to