summaryrefslogtreecommitdiff
path: root/usr.bin/kdump/mksubr
diff options
context:
space:
mode:
authorPhilip Guenthe <guenther@cvs.openbsd.org>2012-07-08 10:23:37 +0000
committerPhilip Guenthe <guenther@cvs.openbsd.org>2012-07-08 10:23:37 +0000
commit1dc039bdab6388c4a8b014f19adb5152243f684f (patch)
treed69c0584ad9fcb6bbe293e2e4b885a3921684a0e /usr.bin/kdump/mksubr
parentb7d68deb634b66a3b798e5f1cbb1ae98f90a9f8e (diff)
Handle the O_ACCMODE bits correctly, so that O_RDONLY is displayed
even when other flag bits are set ok otto@
Diffstat (limited to 'usr.bin/kdump/mksubr')
-rw-r--r--usr.bin/kdump/mksubr57
1 files changed, 54 insertions, 3 deletions
diff --git a/usr.bin/kdump/mksubr b/usr.bin/kdump/mksubr
index 40585ec6c5e..73166171222 100644
--- a/usr.bin/kdump/mksubr
+++ b/usr.bin/kdump/mksubr
@@ -1,5 +1,5 @@
#!/bin/sh
-# $OpenBSD: mksubr,v 1.11 2012/06/20 07:30:01 guenther Exp $
+# $OpenBSD: mksubr,v 1.12 2012/07/08 10:23:36 guenther Exp $
#
# Copyright (c) 2006 David Kirchner <dpk@dpk.net>
#
@@ -48,7 +48,7 @@ include_dir=$1
# Automatically generates a C function that will print out the
# numeric input as a pipe-delimited string of the appropriate
# #define keys. ex:
-# S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH
+# 0x1a4<S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH>
# The XOR is necessary to prevent including the "0"-value in every
# line.
#
@@ -120,6 +120,57 @@ _EOF_
}
#
+# Automatically generates a C function that will print out a
+# file flags input as a pipe-delimited string of the appropriate
+# #define keys. ex:
+# 0x30000<O_RDONLY|O_CLOEXEC|O_DIRECTORY>
+# This is different than the others to handle O_RDONLY correctly when
+# other flags are present and to diagnose an invalid O_ACCMODE value
+#
+auto_fflags_type () {
+ local name grep file
+ name=$1
+ grep=$2
+ file=$3
+
+ cat <<_EOF_
+/* AUTO */
+void
+$name (int arg)
+{
+ printf("%#x<", arg);
+ switch (arg & O_ACCMODE) {
+ case O_RDONLY:
+ printf("O_RDONLY");
+ break;
+ case O_WRONLY:
+ printf("O_WRONLY");
+ break;
+ case O_RDWR:
+ printf("O_RDWR");
+ break;
+ default:
+ printf("<invalid>O_ACCMODE");
+ break;
+ }
+_EOF_
+ egrep "^#[[:space:]]*define[[:space:]]+"${grep}"[[:space:]]*" \
+ $include_dir/$file | \
+ egrep -v 'O_(RD(ONLY|WR)|WRONLY|ACCMODE)' | \
+ awk '{ for (i = 1; i <= NF; i++) \
+ if ($i ~ /define/) \
+ break; \
+ ++i; \
+ printf "\tif (arg & %s) printf (\"|%%s\", \"%s\");\n", $i, $i }'
+cat <<_EOF_
+ printf(">");
+}
+
+_EOF_
+}
+
+
+#
# Automatically generates a C function used when the argument
# maps to a single, specific #definition
#
@@ -400,7 +451,7 @@ sockoptlevelname (int level)
_EOF_
auto_orz_type "modename" "S_[A-Z]+[[:space:]]+[0-6]{7}" "sys/stat.h"
-auto_or_type "flagsname" "O_[A-Z]+[[:space:]]+0x[0-9A-Fa-f]+" "sys/fcntl.h"
+auto_fflags_type "flagsname" "O_[A-Z]+[[:space:]]+0x[0-9A-Fa-f]+" "sys/fcntl.h"
auto_orz_type "atflagsname" "AT_[A-Z_]+[[:space:]]+0x[0-9A-Fa-f]+" "sys/fcntl.h"
auto_or_type "accessmodename" "[A-Z]_OK[[:space:]]+0?x?[0-9A-Fa-f]+" "sys/unistd.h"
auto_or_type "mmapprotname" "PROT_[A-Z]+[[:space:]]+0x[0-9A-Fa-f]+" "sys/mman.h"