2005-05-31  Dmitry V. Levin  <ldv@altlinux.org>

	* util.c (printxval): Change third argument from "char *" to
	"const char *".
	(printflags): Add third argument, "const char *", with similar
	meaning to the third argument of printxval().
	* defs.h (printxval): Change third argument from "char *" to
	"const char *".
	(printflags): Add third argument.
	* bjm.c (sys_query_module) [LINUX]: Pass third argument to
	printflags().
	* desc.c (sys_fcntl): Likewise.
	(sys_flock) [LOCK_SH]: Likewise.
	(print_epoll_event) [HAVE_SYS_EPOLL_H]: Likewise.
	* file.c (sys_open): Likewise.
	(solaris_open) [LINUXSPARC]: Likewise.
	(sys_access): Likewise.
	(sys_chflags, sys_fchflags) [FREEBSD]: Likewise.
	(realprintstat) [HAVE_LONG_LONG_OFF_T &&
	HAVE_STRUCT_STAT_ST_FLAGS]: Likewise.
	(printstat64) [HAVE_STAT64 &&
	HAVE_STRUCT_STAT_ST_FLAGS]: Likewise.
	(sys_setxattr, sys_fsetxattr): Likewise.
	* ipc.c (sys_msgget, sys_msgsnd, sys_msgrcv, sys_semget,
	sys_shmget, sys_shmat) [LINUX || SUNOS4 || FREEBSD]: Likewise.
	(sys_mq_open) [LINUX]: Likewise.
	(printmqattr) [HAVE_MQUEUE_H]: Likewise.
	* mem.c (print_mmap) [!HAVE_LONG_LONG_OFF_T]: Likewise.
	(sys_mmap64) [_LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T]: Likewise.
	(sys_mprotect): Likewise.
	(sys_mremap, sys_madvise, sys_mlockall) [LINUX]: Likewise.
	(sys_msync) [MS_ASYNC]: Likewise.
	(sys_mctl) [MC_SYNC]: Likewise.
	(sys_remap_file_pages, sys_mbind, sys_get_mempolicy) [LINUX]:
	Likewise.
	* net.c (printmsghdr) [HAVE_STRUCT_MSGHDR_MSG_CONTROL]: Likewise.
	(sys_send, sys_sendto): Likewise.
	(sys_sendmsg) [HAVE_SENDMSG]: Likewise.
	(sys_recv, sys_recvfrom): Likewise.
	(sys_recvmsg) [HAVE_SENDMSG]: Likewise.
	(printicmpfilter) [ICMP_FILTER]: Likewise.
	* proc.c (proc_ioctl) [SVR4 && !HAVE_MP_PROCFS || FREEBSD]: Likewise.
	* process.c (sys_clone) [LINUX]: Likewise.
	(printwaitn): Likewise.
	(sys_waitid) [SVR4 || LINUX]: Likewise.
	* signal.c (sys_sigvec) [SUNOS4 || FREEBSD]: Likewise.
	(sys_sigaction): Likewise.
	(printcontext) [SVR4]: Likewise.
	(print_stack_t) [LINUX) || FREEBSD]: Likewise.
	(sys_rt_sigaction) [LINUX]: Likewise.
	* sock.c (sock_ioctl) [LINUX]: Likewise.
	* stream.c (sys_putmsg, sys_getmsg): Likewise.
	(sys_putpmsg) [SYS_putpmsg]: Likewise.
	(sys_getpmsg) [SYS_getpmsg]: Likewise.
	(sys_poll): Likewise.
	(print_transport_message) [TI_BIND]: Likewise.
	(stream_ioctl): Likewise.
	* system.c (sys_mount, sys_reboot): Likewise.
	(sys_cacheflush) [LINUX && M68K]: Likewise.
	(sys_capget, sys_capset) [SYS_capget]: Likewise.
	* term.c (term_ioctl) [TIOCMGET]: Likewise.
	* time.c (sys_clock_nanosleep, sys_timer_settime) [LINUX]:
	Likewise.
	Fixes RH#159310.
diff --git a/bjm.c b/bjm.c
index 3a6be06..68a2185 100644
--- a/bjm.c
+++ b/bjm.c
@@ -118,7 +118,7 @@
 			size_t			ret;
 			umove(tcp, tcp->u_arg[2], &mi);
 			tprintf("{address=%#lx, size=%lu, flags=", mi.addr, mi.size);
-			printflags(modflags, mi.flags);
+			printflags(modflags, mi.flags, "MOD_???");
 			tprintf(", usecount=%lu}", mi.usecount);
 			umove(tcp, tcp->u_arg[4], &ret);
 			tprintf(", %Zu", ret);
diff --git a/defs.h b/defs.h
index 03cad78..574a7d2 100644
--- a/defs.h
+++ b/defs.h
@@ -425,10 +425,10 @@
 extern void newoutf P((struct tcb *));
 extern int get_scno P((struct tcb *));
 extern int trace_syscall P((struct tcb *));
-extern void printxval P((const struct xlat *, int, char *));
+extern void printxval P((const struct xlat *, int, const char *));
 extern int printargs P((struct tcb *));
 extern int addflags P((const struct xlat *, int));
-extern int printflags P((const struct xlat *, int));
+extern int printflags P((const struct xlat *, int, const char *));
 extern int umoven P((struct tcb *, long, int, char *));
 extern int umovestr P((struct tcb *, long, int, char *));
 extern int upeek P((int, long, long *));
diff --git a/desc.c b/desc.c
index 6e864b2..2432b58 100644
--- a/desc.c
+++ b/desc.c
@@ -278,16 +278,14 @@
 		switch (tcp->u_arg[1]) {
 		case F_SETFD:
 			tprintf(", ");
-			if (printflags(fdflags, tcp->u_arg[2]) == 0)
-				tprintf("0");
+			printflags(fdflags, tcp->u_arg[2], "FD_???");
 			break;
 		case F_SETOWN: case F_DUPFD:
 			tprintf(", %ld", tcp->u_arg[2]);
 			break;
 		case F_SETFL:
 			tprintf(", ");
-			if (printflags(openmodes, tcp->u_arg[2] + 1) == 0)
-				tprintf("0");
+			printflags(openmodes, tcp->u_arg[2] + 1, "O_???");
 			break;
 		case F_SETLK: case F_SETLKW:
 #ifdef F_FREESP
@@ -357,8 +355,7 @@
 {
 	if (entering(tcp)) {
 		tprintf("%ld, ", tcp->u_arg[0]);
-		if (!printflags(flockcmds, tcp->u_arg[1]))
-			tprintf("LOCK_???");
+		printflags(flockcmds, tcp->u_arg[1], "LOCK_???");
 	}
 	return 0;
 }
@@ -639,8 +636,7 @@
 struct epoll_event *ev;
 {
 	tprintf("{");
-	if (printflags(epollevents, ev->events) == 0)
-		tprintf("0");
+	printflags(epollevents, ev->events, "EPOLL???");
 	/* We cannot know what format the program uses, so print u32 and u64
 	   which will cover every value.  */
 	tprintf(", {u32=%" PRIu32 ", u64=%" PRIu64 "}}",
diff --git a/file.c b/file.c
index 8a3432f..821d4a8 100644
--- a/file.c
+++ b/file.c
@@ -315,7 +315,7 @@
 		printpath(tcp, tcp->u_arg[0]);
 		tprintf(", ");
 		/* flags */
-		printflags(openmodes, tcp->u_arg[1] + 1);
+		printflags(openmodes, tcp->u_arg[1] + 1, "O_???");
 		if (tcp->u_arg[1] & O_CREAT) {
 			/* mode */
 			tprintf(", %#lo", tcp->u_arg[2]);
@@ -351,7 +351,7 @@
 		printpath(tcp, tcp->u_arg[0]);
 		tprintf(", ");
 		/* flags */
-		printflags(openmodessol, tcp->u_arg[1] + 1);
+		printflags(openmodessol, tcp->u_arg[1] + 1, "O_???");
 		if (tcp->u_arg[1] & 0x100) {
 			/* mode */
 			tprintf(", %#lo", tcp->u_arg[2]);
@@ -394,7 +394,7 @@
 	if (entering(tcp)) {
 		printpath(tcp, tcp->u_arg[0]);
 		tprintf(", ");
-		printflags(access_flags, tcp->u_arg[1]);
+		printflags(access_flags, tcp->u_arg[1], "?_OK");
 	}
 	return 0;
 }
@@ -783,10 +783,7 @@
 	if (entering(tcp)) {
 		printpath(tcp, tcp->u_arg[0]);
 		tprintf(", ");
-		if (tcp->u_arg[1])
-			printflags(fileflags, tcp->u_arg[1]);
-		else
-			tprintf("0");
+		printflags(fileflags, tcp->u_arg[1], "UF_???");
 	}
 	return 0;
 }
@@ -797,10 +794,7 @@
 {
 	if (entering(tcp)) {
 		tprintf("%ld, ", tcp->u_arg[0]);
-		if (tcp->u_arg[1])
-			printflags(fileflags, tcp->u_arg[1]);
-		else
-			tprintf("0");
+		printflags(fileflags, tcp->u_arg[1], "UF_???");
 	}
 	return 0;
 }
@@ -853,10 +847,7 @@
 	    tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
 #if HAVE_STRUCT_STAT_ST_FLAGS
 		tprintf(", st_flags=");
-		if (statbuf->st_flags) {
-			printflags(fileflags, statbuf->st_flags);
-		} else
-			tprintf("0");
+		printflags(fileflags, statbuf->st_flags, "UF_???");
 #endif
 #if HAVE_STRUCT_STAT_ST_ACLCNT
 		tprintf(", st_aclcnt=%d", statbuf->st_aclcnt);
@@ -999,10 +990,7 @@
 		tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
 #if HAVE_STRUCT_STAT_ST_FLAGS
 		tprintf(", st_flags=");
-		if (statbuf.st_flags) {
-			printflags(fileflags, statbuf.st_flags);
-		} else
-			tprintf("0");
+		printflags(fileflags, statbuf.st_flags, "UF_???");
 #endif
 #if HAVE_STRUCT_STAT_ST_ACLCNT
 		tprintf(", st_aclcnt=%d", statbuf.st_aclcnt);
@@ -2403,7 +2391,7 @@
 	printstr(tcp, tcp->u_arg[1], -1);
 	print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
 	tprintf(", ");
-	printflags(xattrflags, tcp->u_arg[4]);
+	printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
     }
     return 0;
 }
@@ -2417,7 +2405,7 @@
 	printstr(tcp, tcp->u_arg[1], -1);
 	print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
 	tprintf(", ");
-	printflags(xattrflags, tcp->u_arg[4]);
+	printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
     }
     return 0;
 }
diff --git a/ipc.c b/ipc.c
index 60fece0..ede16b9 100644
--- a/ipc.c
+++ b/ipc.c
@@ -162,7 +162,7 @@
 		else
 			tprintf("IPC_PRIVATE");
 		tprintf(", ");
-		if (printflags(resource_flags, tcp->u_arg[1] & ~0777) != 0)
+		if (printflags(resource_flags, tcp->u_arg[1] & ~0777, NULL) != 0)
 			tprintf("|");
 		tprintf("%#lo", tcp->u_arg[1] & 0777);
 	}
@@ -206,8 +206,7 @@
 			tcp->u_arg[1]);
 		tprintf("}, %lu", tcp->u_arg[1]);
 		tprintf(", ");
-		if (printflags(msg_flags, tcp->u_arg[2]) == 0)
-			tprintf("0");
+		printflags(msg_flags, tcp->u_arg[2], "MSG_???");
 #else /* !LINUX */
 		umove(tcp, tcp->u_arg[1], &mtype);
 		tprintf(", {%lu, ", mtype);
@@ -215,8 +214,7 @@
 			tcp->u_arg[2]);
 		tprintf("}, %lu", tcp->u_arg[2]);
 		tprintf(", ");
-		if (printflags(msg_flags, tcp->u_arg[3]) == 0)
-			tprintf("0");
+		printflags(msg_flags, tcp->u_arg[3], "MSG_???");
 #endif /* !LINUX */
 	}
 	return 0;
@@ -245,8 +243,7 @@
 		tprintf("}, %lu", tcp->u_arg[1]);
 		tprintf(", %ld", tmp.msgtyp);
 		tprintf(", ");
-		if (printflags(msg_flags, tcp->u_arg[2]) == 0)
-			tprintf("0");
+		printflags(msg_flags, tcp->u_arg[2], "MSG_???");
 #else /* !LINUX */
 		umove(tcp, tcp->u_arg[1], &mtype);
 		tprintf(", {%lu, ", mtype);
@@ -255,8 +252,7 @@
 		tprintf("}, %lu", tcp->u_arg[2]);
 		tprintf(", %ld", tcp->u_arg[3]);
 		tprintf(", ");
-		if (printflags(msg_flags, tcp->u_arg[4]) == 0)
-			tprintf("0");
+		printflags(msg_flags, tcp->u_arg[4], "MSG_???");
 #endif /* !LINUX */
 	}
 	return 0;
@@ -302,7 +298,7 @@
 			tprintf("IPC_PRIVATE");
 		tprintf(", %lu", tcp->u_arg[1]);
 		tprintf(", ");
-		if (printflags(resource_flags, tcp->u_arg[2] & ~0777) != 0)
+		if (printflags(resource_flags, tcp->u_arg[2] & ~0777, NULL) != 0)
 			tprintf("|");
 		tprintf("%#lo", tcp->u_arg[2] & 0777);
 	}
@@ -331,7 +327,7 @@
 			tprintf("IPC_PRIVATE");
 		tprintf(", %lu", tcp->u_arg[1]);
 		tprintf(", ");
-		if (printflags(shm_resource_flags, tcp->u_arg[2] & ~0777) != 0)
+		if (printflags(shm_resource_flags, tcp->u_arg[2] & ~0777, NULL) != 0)
 			tprintf("|");
 		tprintf("%#lo", tcp->u_arg[2] & 0777);
 	}
@@ -365,13 +361,11 @@
 #ifdef LINUX
 		tprintf(", %#lx", tcp->u_arg[3]);
 		tprintf(", ");
-		if (printflags(shm_flags, tcp->u_arg[1]) == 0)
-			tprintf("0");
+		printflags(shm_flags, tcp->u_arg[1], "SHM_???");
 #else /* !LINUX */
 		tprintf(", %#lx", tcp->u_arg[1]);
 		tprintf(", ");
-		if (printflags(shm_flags, tcp->u_arg[2]) == 0)
-			tprintf("0");
+		printflags(shm_flags, tcp->u_arg[2], "SHM_???");
 #endif /* !LINUX */
 		if (syserror(tcp))
 			return 0;
@@ -407,7 +401,7 @@
 		printpath(tcp, tcp->u_arg[0]);
 		tprintf(", ");
 		/* flags */
-		printflags(openmodes, tcp->u_arg[1] + 1);
+		printflags(openmodes, tcp->u_arg[1] + 1, "O_???");
 		if (tcp->u_arg[1] & O_CREAT) {
 # ifndef HAVE_MQUEUE_H
 			tprintf(", %lx", tcp->u_arg[2]);
@@ -477,7 +471,7 @@
 			return;
 		}
 		tprintf("{mq_flags=");
-		printflags(openmodes, attr.mq_flags + 1);
+		printflags(openmodes, attr.mq_flags + 1, "O_???");
 		tprintf(", mq_maxmsg=%ld, mq_msgsize=%ld, mq_curmsg=%ld}",
 			attr.mq_maxmsg, attr.mq_msgsize, attr.mq_curmsgs);
 # endif
diff --git a/mem.c b/mem.c
index fbc26da..08a5f92 100644
--- a/mem.c
+++ b/mem.c
@@ -199,14 +199,14 @@
 		/* len */
 		tprintf("%lu, ", u_arg[1]);
 		/* prot */
-		printflags(mmap_prot, u_arg[2]);
+		printflags(mmap_prot, u_arg[2], "PROT_???");
 		tprintf(", ");
 		/* flags */
 #ifdef MAP_TYPE
 		printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
 		addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
 #else
-		printflags(mmap_flags, u_arg[3]);
+		printflags(mmap_flags, u_arg[3], "MAP_???");
 #endif
 		/* fd (is always int, not long) */
 		tprintf(", %d, ", (int)u_arg[4]);
@@ -300,14 +300,14 @@
 		/* len */
 		tprintf("%lu, ", u_arg[1]);
 		/* prot */
-		printflags(mmap_prot, u_arg[2]);
+		printflags(mmap_prot, u_arg[2], "PROT_???");
 		tprintf(", ");
 		/* flags */
 #ifdef MAP_TYPE
 		printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
 		addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
 #else
-		printflags(mmap_flags, u_arg[3]);
+		printflags(mmap_flags, u_arg[3], "MAP_???");
 #endif
 		/* fd */
 		tprintf(", %ld, ", u_arg[4]);
@@ -337,8 +337,7 @@
 	if (entering(tcp)) {
 		tprintf("%#lx, %lu, ",
 			tcp->u_arg[0], tcp->u_arg[1]);
-		if (!printflags(mmap_prot, tcp->u_arg[2]))
-			tprintf("PROT_???");
+		printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
 	}
 	return 0;
 }
@@ -357,7 +356,7 @@
 	if (entering(tcp)) {
 		tprintf("%#lx, %lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1],
 			tcp->u_arg[2]);
-		printflags(mremap_flags, tcp->u_arg[3]);
+		printflags(mremap_flags, tcp->u_arg[3], "MREMAP_???");
 	}
 	return RVAL_HEX;
 }
@@ -388,7 +387,7 @@
 {
 	if (entering(tcp)) {
 		tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
-		printflags(madvise_flags, tcp->u_arg[2]);
+		printflags(madvise_flags, tcp->u_arg[2], "MADV_???");
 	}
 	return 0;
 }
@@ -409,7 +408,7 @@
 struct tcb *tcp;
 {
 	if (entering(tcp)) {
-		printflags(mlockall_flags, tcp->u_arg[0]);
+		printflags(mlockall_flags, tcp->u_arg[0], "MCL_???");
 	}
 	return 0;
 }
@@ -438,8 +437,7 @@
 		/* len */
 		tprintf(", %lu, ", tcp->u_arg[1]);
 		/* flags */
-		if (!printflags(mctl_sync, tcp->u_arg[2]))
-			tprintf("MS_???");
+		printflags(mctl_sync, tcp->u_arg[2], "MS_???");
 	}
 	return 0;
 }
@@ -476,19 +474,16 @@
 		tprintf(", %lu, ", tcp->u_arg[1]);
 		/* function */
 		function = tcp->u_arg[2];
-		if (!printflags(mctl_funcs, function))
-			tprintf("MC_???");
+		printflags(mctl_funcs, function, "MC_???");
 		/* arg */
 		arg = tcp->u_arg[3];
 		tprintf(", ");
 		switch (function) {
 		case MC_SYNC:
-			if (!printflags(mctl_sync, arg))
-				tprintf("MS_???");
+			printflags(mctl_sync, arg, "MS_???");
 			break;
 		case MC_LOCKAS:
-			if (!printflags(mctl_lockas, arg))
-				tprintf("MCL_???");
+			printflags(mctl_lockas, arg, "MCL_???");
 			break;
 		default:
 			tprintf("%#x", arg);
@@ -646,13 +641,13 @@
 {
 	if (entering(tcp)) {
 		tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
-		printflags(mmap_prot, tcp->u_arg[2]);
+		printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
 		tprintf(", %lu, ", tcp->u_arg[3]);
 #ifdef MAP_TYPE
 		printxval(mmap_flags, tcp->u_arg[4] & MAP_TYPE, "MAP_???");
 		addflags(mmap_flags, tcp->u_arg[4] & ~MAP_TYPE);
 #else
-		printflags(mmap_flags, tcp->u_arg[4]);
+		printflags(mmap_flags, tcp->u_arg[4], "MAP_???");
 #endif
 	}
 	return 0;
@@ -729,8 +724,7 @@
 		printxval(policies, tcp->u_arg[2], "MPOL_???");
 		get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[4], 0);
 		tprintf(", ");
-		if (printflags(mbindflags, tcp->u_arg[5]) == 0)
-			tprintf("0");
+		printflags(mbindflags, tcp->u_arg[5], "MPOL_???");
 	}
 	return 0;
 }
@@ -760,8 +754,7 @@
 			printxval(policies, pol, "MPOL_???");
 		get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], syserror(tcp));
 		tprintf(", %#lx, ", tcp->u_arg[3]);
-		if (printflags(mempolicyflags, tcp->u_arg[4]) == 0)
-			tprintf("0");
+		printflags(mempolicyflags, tcp->u_arg[4], "MPOL_???");
 	}
 	return 0;
 }
diff --git a/net.c b/net.c
index 593ccf3..103278d 100644
--- a/net.c
+++ b/net.c
@@ -1146,8 +1146,7 @@
 		printcmsghdr(tcp, (unsigned long) msg.msg_control,
 			     msg.msg_controllen);
 	tprintf(", msg_flags=");
-	if (printflags(msg_flags, msg.msg_flags)==0)
-		tprintf("0");
+	printflags(msg_flags, msg.msg_flags, "MSG_???");
 #else /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
 	tprintf("msg_accrights=%#lx, msg_accrightslen=%u",
 		(unsigned long) msg.msg_accrights, msg.msg_accrightslen);
@@ -1274,8 +1273,7 @@
 		printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
 		tprintf(", %lu, ", tcp->u_arg[2]);
 		/* flags */
-		if (printflags(msg_flags, tcp->u_arg[3]) == 0)
-			tprintf("0");
+		printflags(msg_flags, tcp->u_arg[3], "MSG_???");
 	}
 	return 0;
 }
@@ -1289,8 +1287,7 @@
 		printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
 		tprintf(", %lu, ", tcp->u_arg[2]);
 		/* flags */
-		if (printflags(msg_flags, tcp->u_arg[3]) == 0)
-			tprintf("0");
+		printflags(msg_flags, tcp->u_arg[3], "MSG_???");
 		/* to address */
 		tprintf(", ");
 		printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
@@ -1311,8 +1308,7 @@
 		printmsghdr(tcp, tcp->u_arg[1]);
 		/* flags */
 		tprintf(", ");
-		if (printflags(msg_flags, tcp->u_arg[2]) == 0)
-			tprintf("0");
+		printflags(msg_flags, tcp->u_arg[2], "MSG_???");
 	}
 	return 0;
 }
@@ -1332,8 +1328,7 @@
 			printstr(tcp, tcp->u_arg[1], tcp->u_rval);
 
 		tprintf(", %lu, ", tcp->u_arg[2]);
-		if (printflags(msg_flags, tcp->u_arg[3]) == 0)
-			tprintf("0");
+		printflags(msg_flags, tcp->u_arg[3], "MSG_???");
 	}
 	return 0;
 }
@@ -1358,8 +1353,7 @@
 		/* len */
 		tprintf(", %lu, ", tcp->u_arg[2]);
 		/* flags */
-		if (printflags(msg_flags, tcp->u_arg[3]) == 0)
-			tprintf("0");
+		printflags(msg_flags, tcp->u_arg[3], "MSG_???");
 		/* from address, len */
 		if (!tcp->u_arg[4] || !tcp->u_arg[5]) {
 			if (tcp->u_arg[4] == 0)
@@ -1399,8 +1393,7 @@
 			printmsghdr(tcp, tcp->u_arg[1]);
 		/* flags */
 		tprintf(", ");
-		if (printflags(msg_flags, tcp->u_arg[2]) == 0)
-			tprintf("0");
+		printflags(msg_flags, tcp->u_arg[2], "MSG_???");
 	}
 	return 0;
 }
@@ -1623,8 +1616,7 @@
 	}
 
 	tprintf("~(");
-	if (printflags(icmpfilterflags, ~filter.data) == 0)
-		tprintf("0");
+	printflags(icmpfilterflags, ~filter.data, "ICMP_???");
 	tprintf(")");
 }
 #endif /* ICMP_FILTER */
diff --git a/proc.c b/proc.c
index 5752144..6916799 100644
--- a/proc.c
+++ b/proc.c
@@ -110,8 +110,7 @@
 			tprintf(", {...}");
 		else {
 			tprintf(", {pr_flags=");
-			if (!printflags(proc_status_flags, status.pr_flags))
-				tprintf("0");
+			printflags(proc_status_flags, status.pr_flags, "PR_???");
 			if (status.pr_why) {
 				tprintf(", pr_why=");
 				printxval(proc_status_why, status.pr_why,
@@ -142,8 +141,7 @@
 			tprintf(", {...}");
 		else {
 			tprintf(", {pr_flags=");
-			if (!printflags(proc_run_flags, run.pr_flags))
-				tprintf("0");
+			printflags(proc_run_flags, run.pr_flags, "PR???");
 			tprintf(", ...}");
 		}
 		return 1;
@@ -154,8 +152,7 @@
 			tprintf(", [?]");
 		else {
 			tprintf(", [");
-			if (!printflags(proc_status_flags, val))
-				tprintf("0");
+			printflags(proc_status_flags, val, "PR_???");
 			tprintf("]");
 		}
 		return 1;
@@ -227,29 +224,22 @@
 			tprintf(", {...}");
 		else {
 			tprintf(", {state=%d, flags=", status.state);
-			if (!printflags(proc_status_flags, status.flags))
-				tprintf("0");
+			printflags(proc_status_flags, status.flags, "PF_???");
 			tprintf(", events=");
-			printflags(proc_status_why, status.events);
+			printflags(proc_status_why, status.events, "S_???");
 			tprintf(", why=");
 			printxval(proc_status_why, status.why, "S_???");
 			tprintf(", val=%lu}", status.val);
 		}
 		return 1;
 	case PIOCBIS:
-		if (arg) {
-			tprintf(", ");
-			printflags(proc_status_why, arg);
-		} else
-			tprintf(", 0");
+		tprintf(", ");
+		printflags(proc_status_why, arg, "S_???");
 		return 1;
 		return 1;
 	case PIOCSFL:
-		if (arg) {
-			tprintf(", ");
-			printflags(proc_status_flags, arg);
-		} else
-			tprintf(", 0");
+		tprintf(", ");
+		printflags(proc_status_flags, arg, "PF_???");
 		return 1;
 	case PIOCGFL:
 	        if (syserror(tcp))
@@ -258,10 +248,7 @@
 			tprintf(", {...}");
 		else {
 			tprintf(", [");
-			if (val)
-				printflags(proc_status_flags, val);
-			else
-				tprintf("0");
+			printflags(proc_status_flags, val, "PF_???");
 			tprintf("]");
 		}
 		return 1;
diff --git a/process.c b/process.c
index 56d1569..badcba6 100644
--- a/process.c
+++ b/process.c
@@ -579,8 +579,7 @@
 				tcp->u_arg[ARG_STACKSIZE]);
 # endif
 		tprintf("flags=");
-		if (printflags(clone_flags, flags &~ CSIGNAL) == 0)
-			tprintf("0");
+		printflags(clone_flags, flags &~ CSIGNAL, NULL);
 		if ((flags & CSIGNAL) != 0)
 			tprintf("|%s", signame(flags & CSIGNAL));
 		if ((flags & (CLONE_PARENT_SETTID|CLONE_CHILD_SETTID
@@ -1820,8 +1819,7 @@
 			exited = printstatus(status);
 		/* options */
 		tprintf(", ");
-		if (!printflags(wait4_options, tcp->u_arg[2]))
-			tprintf("0");
+		printflags(wait4_options, tcp->u_arg[2], "W???");
 		if (n == 4) {
 			tprintf(", ");
 			/* usage */
@@ -2045,8 +2043,7 @@
 			printsiginfo(&si, verbose (tcp));
 		/* options */
 		tprintf(", ");
-		if (!printflags(wait4_options, tcp->u_arg[3]))
-			tprintf("0");
+		printflags(wait4_options, tcp->u_arg[3], "W???");
 		if (tcp->u_nargs > 4) {
 			/* usage */
 			tprintf(", ");
diff --git a/signal.c b/signal.c
index f7c9f66..2df70a0 100644
--- a/signal.c
+++ b/signal.c
@@ -962,8 +962,7 @@
 			tprintf("{%#lx, ", (unsigned long) sv.sv_handler);
 			printsigmask(&sv.sv_mask, 0);
 			tprintf(", ");
-			if (!printflags(sigvec_flags, sv.sv_flags))
-				tprintf("0");
+			printflags(sigvec_flags, sv.sv_flags, "SV_???");
 			tprintf("}");
 		}
 	}
@@ -1128,8 +1127,7 @@
 			printsigmask(&sigset, 0);
 #endif
 			tprintf(", ");
-			if (!printflags(sigact_flags, sa.sa_flags))
-				tprintf("0");
+			printflags(sigact_flags, sa.sa_flags, "SA_???");
 #ifdef SA_RESTORER
 			if (sa.sa_flags & SA_RESTORER)
 				tprintf(", %p", sa.sa_restorer);
@@ -1541,8 +1539,7 @@
 	tprintf("{");
 	if (!abbrev(tcp)) {
 		tprintf("uc_flags=");
-		if (!printflags(ucontext_flags, ucp->uc_flags))
-			tprintf("0");
+		printflags(ucontext_flags, ucp->uc_flags, "UC_???");
 		tprintf(", uc_link=%#lx, ", (unsigned long) ucp->uc_link);
 	}
 	tprintf("uc_sigmask=");
@@ -1551,8 +1548,7 @@
 		tprintf(", uc_stack={ss_sp=%#lx, ss_size=%d, ss_flags=",
 			(unsigned long) ucp->uc_stack.ss_sp,
 			ucp->uc_stack.ss_size);
-		if (!printflags(sigaltstack_flags, ucp->uc_stack.ss_flags))
-			tprintf("0");
+		printflags(sigaltstack_flags, ucp->uc_stack.ss_flags, "SS_???");
 		tprintf("}");
 	}
 	tprintf(", ...}");
@@ -1613,8 +1609,7 @@
 	if (umove(tcp, addr, &ss) < 0)
 		return -1;
 	tprintf("{ss_sp=%#lx, ss_flags=", (unsigned long) ss.ss_sp);
-	if (!printflags(sigaltstack_flags, ss.ss_flags))
-		tprintf("0");
+	printflags(sigaltstack_flags, ss.ss_flags, "SS_???");
 	tprintf(", ss_size=%lu}", (unsigned long) ss.ss_size);
 	return 0;
 }
@@ -1857,8 +1852,7 @@
 					memcpy(&sigset, &sa.sa_mask, sizeof(sigset));
 				printsigmask(&sigset, 1);
 				tprintf(", ");
-				if (!printflags(sigact_flags, sa.sa_flags))
-					tprintf("0");
+				printflags(sigact_flags, sa.sa_flags, "SA_???");
 #ifdef SA_RESTORER
 				if (sa.sa_flags & SA_RESTORER)
 					tprintf(", %p", sa.sa_restorer);
diff --git a/sock.c b/sock.c
index 787bf92..462df22 100644
--- a/sock.c
+++ b/sock.c
@@ -193,7 +193,7 @@
 				break;
 			case SIOCGIFFLAGS:
 				tprintf("ifr_flags=");
-				printflags(iffflags, ifr.ifr_flags);
+				printflags(iffflags, ifr.ifr_flags, "IFF_???");
 				break;
 			case SIOCGIFMETRIC:
 				tprintf("ifr_metric=%d", ifr.ifr_metric);
diff --git a/stream.c b/stream.c
index 68be3a4..998fd8a 100644
--- a/stream.c
+++ b/stream.c
@@ -124,8 +124,7 @@
 		for (i = 1; i < 3; i++)
 			printstrbufarg(tcp, tcp->u_arg[i], 0);
 		/* flags */
-		if (!printflags(msgflags, tcp->u_arg[3]))
-			tprintf("0");
+		printflags(msgflags, tcp->u_arg[3], "RS_???");
 	}
 	return 0;
 }
@@ -155,8 +154,7 @@
 			tprintf("[?]");
 		else {
 			tprintf("[");
-			if (!printflags(msgflags, flags))
-				tprintf("0");
+			printflags(msgflags, flags, "RS_???");
 			tprintf("]");
 		}
 		/* decode return value */
@@ -209,8 +207,7 @@
 		/* band */
 		tprintf("%ld, ", tcp->u_arg[3]);
 		/* flags */
-		if (!printflags(pmsgflags, tcp->u_arg[4]))
-			tprintf("0");
+		printflags(pmsgflags, tcp->u_arg[4], "MSG_???");
 	}
 	return 0;
 }
@@ -245,8 +242,7 @@
 			tprintf("[?]");
 		else {
 			tprintf("[");
-			if (!printflags(pmsgflags, flags))
-				tprintf("0");
+			printflags(pmsgflags, flags, "MSG_???");
 			tprintf("]");
 		}
 		/* decode return value */
@@ -334,13 +330,12 @@
 					continue;
 				}
 				tprintf("{fd=%d, events=", pollp[i].fd);
-				if (!printflags(pollflags, pollp[i].events))
-					tprintf("0");
+				printflags(pollflags, pollp[i].events,
+					   "POLL???");
 				if (!syserror(tcp) && pollp[i].revents) {
 					tprintf(", revents=");
-					if (!printflags(pollflags,
-							pollp[i].revents))
-						tprintf("0");
+					printflags(pollflags, pollp[i].revents,
+						   "POLL???");
 				}
 				tprintf("}");
 			}
@@ -774,7 +769,8 @@
 		GET (T_OPTMGMT_REQ, optmgmt_req);
 		COMMA ();
 		tprintf ("MGMT=");
-		printflags (transport_user_flags, m.optmgmt_req.MGMT_flags);
+		printflags (transport_user_flags, m.optmgmt_req.MGMT_flags,
+			    "T_???");
 		STRUCT (optmgmt_req, OPT, print_optmgmt);
 		break;
 #endif
@@ -834,7 +830,7 @@
 		tprintf (", CURRENT=");
 		printxval (ts_state, m.info_ack.CURRENT_state, "TS_???");
 		tprintf (", PROVIDER=");
-		printflags (provider_flags, m.info_ack.PROVIDER_flag);
+		printflags (provider_flags, m.info_ack.PROVIDER_flag, "???");
 		break;
 #endif
 #ifdef T_BIND_ACK
@@ -885,7 +881,8 @@
 		GET (T_OPTMGMT_ACK, optmgmt_ack);
 		COMMA ();
 		tprintf ("MGMT=");
-		printflags (transport_user_flags, m.optmgmt_ack.MGMT_flags);
+		printflags (transport_user_flags, m.optmgmt_ack.MGMT_flags,
+			    "T_???");
 		STRUCT (optmgmt_ack, OPT, print_optmgmt);
 		break;
 #endif
@@ -1127,8 +1124,7 @@
 			tprintf(", {...}");
 		else {
 			tprintf(", {bi_pri=%d, bi_flag=", bi.bi_pri);
-			if (!printflags(stream_flush_options, bi.bi_flag))
-				tprintf("0");
+			printflags(stream_flush_options, bi.bi_flag, "FLUSH???");
 			tprintf("}");
 		}
 		return 1;
@@ -1136,8 +1132,7 @@
 	case I_SETSIG:
 		/* argument is a set of flags */
 		tprintf(", ");
-		if (!printflags(stream_setsig_flags, arg))
-			tprintf("0");
+		printflags(stream_setsig_flags, arg, "S_???");
 		return 1;
 	case I_GETSIG:
 		/* argument is a pointer to a set of flags */
@@ -1146,8 +1141,8 @@
 		tprintf(", [");
 		if (umove(tcp, arg, &val) < 0)
 			tprintf("?");
-		else if (!printflags(stream_setsig_flags, val))
-			tprintf("0");
+		else
+			printflags(stream_setsig_flags, val, "S_???");
 		tprintf("]");
 		return 1;
 	case I_PEEK:
@@ -1163,8 +1158,7 @@
 		tprintf(", databuf=");
 		printstrbuf(tcp, &sp.databuf, 1);
 		tprintf(", flags=");
-		if (!printflags(msgflags, sp.flags))
-			tprintf("0");
+		printflags(msgflags, sp.flags, "RS_???");
 		tprintf("}");
 		return 1;
 	case I_SRDOPT:
@@ -1216,16 +1210,14 @@
 		tprintf(", databuf=");
 		printstrbuf(tcp, &sfi.databuf, 1);
 		tprintf(", flags=");
-		if (!printflags(msgflags, sfi.flags))
-			tprintf("0");
+		printflags(msgflags, sfi.flags, "RS_???");
 		tprintf(", filedes=%d, offset=%d}", sfi.fildes, sfi.offset);
 		return 1;
 #ifdef I_SWROPT
 	case I_SWROPT:
 		/* argument is a set of flags */
 		tprintf(", ");
-		if (!printflags(stream_write_flags, arg))
-			tprintf("0");
+		printflags(stream_write_flags, arg, "SND???");
 		return 1;
 #endif /* I_SWROPT */
 #ifdef I_GWROPT
@@ -1236,8 +1228,8 @@
 		tprintf(", [");
 		if (umove(tcp, arg, &val) < 0)
 			tprintf("?");
-		else if (!printflags(stream_write_flags, arg))
-			tprintf("0");
+		else
+			printflags(stream_write_flags, arg, "SND???");
 		tprintf("]");
 		return 1;
 #endif /* I_GWROPT */
diff --git a/system.c b/system.c
index 623571c..7bbcdcd 100644
--- a/system.c
+++ b/system.c
@@ -112,7 +112,7 @@
 		else
 			tprintf("%#lx", tcp->u_arg[2]);
 		tprintf(", ");
-		printflags(mount_flags, tcp->u_arg[3]);
+		printflags(mount_flags, tcp->u_arg[3], "MS_???");
 		tprintf(", %#lx", tcp->u_arg[4]);
 	}
 	return 0;
@@ -197,14 +197,11 @@
 struct tcb *tcp;
 {
 	if (entering(tcp)) {
-		if (!printflags(bootflags1, tcp->u_arg[0]))
-			tprintf("LINUX_REBOOT_MAGIC???");
+		printflags(bootflags1, tcp->u_arg[0], "LINUX_REBOOT_MAGIC_???");
 		tprintf(", ");
-		if (!printflags(bootflags2, tcp->u_arg[1]))
-			tprintf("LINUX_REBOOT_MAGIC???");
+		printflags(bootflags2, tcp->u_arg[1], "LINUX_REBOOT_MAGIC_???");
 		tprintf(", ");
-		if (!printflags(bootflags3, tcp->u_arg[2]))
-			tprintf("LINUX_REBOOT_CMD_???");
+		printflags(bootflags3, tcp->u_arg[2], "LINUX_REBOOT_CMD_???");
 		if (tcp->u_arg[2] == LINUX_REBOOT_CMD_RESTART2) {
 			tprintf(", ");
 			printstr(tcp, tcp->u_arg[3], -1);
@@ -251,7 +248,7 @@
 		printxval(cacheflush_scope, tcp->u_arg[1], "FLUSH_SCOPE_???");
 		tprintf(", ");
 		/* flags */
-		printflags(cacheflush_flags, tcp->u_arg[2]);
+		printflags(cacheflush_flags, tcp->u_arg[2], "FLUSH_CACHE_???");
 		/* len */
 		tprintf(", %lu", tcp->u_arg[3]);
 	}
@@ -302,8 +299,7 @@
 struct tcb *tcp;
 {
 	if (entering(tcp)) {
-		if (!printflags(bootflags, tcp->u_arg[0]))
-			tprintf("RB_???");
+		printflags(bootflags, tcp->u_arg[0], "RB_???");
 		if (tcp->u_arg[0] & RB_STRING) {
 			printstr(tcp, tcp->u_arg[1], -1);
 		}
@@ -401,8 +397,7 @@
 		}
 		printstr(tcp, tcp->u_arg[1], -1);
 		tprintf(", ");
-		if (!printflags(mountflags, tcp->u_arg[2] & ~M_NEWTYPE))
-			tprintf("0");
+		printflags(mountflags, tcp->u_arg[2] & ~M_NEWTYPE, "M_???");
 		tprintf(", ");
 
 		if (strcmp(type, "4.2") == 0) {
@@ -422,8 +417,7 @@
 			tprintf("[");
 			printsock(tcp, (int) a.addr);
 			tprintf(", ");
-			if (!printflags(nfsflags, a.flags))
-				tprintf("NFSMNT_???");
+			printflags(nfsflags, a.flags, "NFSMNT_???");
 			tprintf(", ws:%u,rs:%u,to:%u,re:%u,",
 				a.wsize, a.rsize, a.timeo, a.retrans);
 			if (a.flags & NFSMNT_HOSTNAME && a.hostname)
@@ -1216,7 +1210,7 @@
 		tprintf(", ");
 		printpath(tcp, tcp->u_arg[1]);
 		tprintf(", ");
-		printflags(mount_flags, tcp->u_arg[2]);
+		printflags(mount_flags, tcp->u_arg[2], "MS_???");
 		if (tcp->u_arg[2] & (MS_FSS | MS_DATA)) {
 			tprintf(", ");
 			tprintf("%ld", tcp->u_arg[3]);
@@ -1233,8 +1227,7 @@
 					tprintf("addr=");
 					printsock(tcp, (int) args.addr);
 					tprintf(", flags=");
-					if (!printflags(nfs_flags, args.flags))
-						tprintf("NFSMNT_???");
+					printflags(nfs_flags, args.flags, "NFSMNT_???");
 					tprintf(", hostname=");
 					printstr(tcp, (int) args.hostname, -1);
 					tprintf(", ...}");
@@ -1329,7 +1322,7 @@
 		tprintf(", ");
 		printpath(tcp, tcp->u_arg[1]);
 		tprintf(", ");
-		printflags(mount_flags, tcp->u_arg[2]);
+		printflags(mount_flags, tcp->u_arg[2], "MS_???");
 		/* The doc sez that the file system type is given as a
 		   fsindex, and we should use sysfs to work out the name.
 		   This appears to be untrue for UW.  Maybe it's untrue
@@ -1353,8 +1346,7 @@
 					tprintf("%#lx", tcp->u_arg[4]);
 				else {
 					tprintf("{ flags=");
-					if (!printflags(vxfs_flags, args.mflags))
-						tprintf("0x%08x", args.mflags);
+					printflags(vxfs_flags, args.mflags, "VX_MS_???");
 					if (args.mflags & VX_MS_SNAPSHOT) {
 						tprintf (", snapof=");
 						printstr (tcp,
@@ -1387,8 +1379,7 @@
 						printsock(tcp, (int) addr.buf, addr.len);
 					}
 					tprintf(", flags=");
-					if (!printflags(nfs_flags, args.flags))
-						tprintf("NFSMNT_???");
+					printflags(nfs_flags, args.flags, "NFSMNT_???");
 					tprintf(", hostname=");
 					printstr(tcp, (int) args.hostname, -1);
 					tprintf(", ...}");
@@ -1497,11 +1488,11 @@
 			tprintf("???");
 		else {
 			tprintf("{");
-			printflags(capabilities, arg1->effective);
+			printflags(capabilities, arg1->effective, "CAP_???");
 			tprintf(", ");
-			printflags(capabilities, arg1->permitted);
+			printflags(capabilities, arg1->permitted, "CAP_???");
 			tprintf(", ");
-			printflags(capabilities, arg1->inheritable);
+			printflags(capabilities, arg1->inheritable, "CAP_???");
 			tprintf("}");
 		}
 	}
@@ -1549,11 +1540,11 @@
 			tprintf("???");
 		else {
 			tprintf("{");
-			printflags(capabilities, arg1->effective);
+			printflags(capabilities, arg1->effective, "CAP_???");
 			tprintf(", ");
-			printflags(capabilities, arg1->permitted);
+			printflags(capabilities, arg1->permitted, "CAP_???");
 			tprintf(", ");
-			printflags(capabilities, arg1->inheritable);
+			printflags(capabilities, arg1->inheritable, "CAP_???");
 			tprintf("}");
 		}
 	}
diff --git a/term.c b/term.c
index e4bf2f8..15897bd 100644
--- a/term.c
+++ b/term.c
@@ -340,8 +340,7 @@
 		if (umove(tcp, arg, &arg) < 0)
 			return 0;
 		tprintf(", [");
-		if (!printflags(modem_flags, arg))
-			tprintf("0");
+		printflags(modem_flags, arg, "TIOCM_???");
 		tprintf("]");
 		return 1;
 #endif /* TIOCMGET */
diff --git a/time.c b/time.c
index 5176f53..b27a71e 100644
--- a/time.c
+++ b/time.c
@@ -411,8 +411,7 @@
 	if (entering(tcp)) {
 		printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
 		tprintf(", ");
-		if (printflags(clockflags, tcp->u_arg[1]) == 0)
-			tprintf("0");
+		printflags(clockflags, tcp->u_arg[1], "TIMER_???");
 		tprintf(", ");
 		printtv(tcp, tcp->u_arg[2]);
 		tprintf(", ");
@@ -493,8 +492,7 @@
 {
 	if (entering(tcp)) {
 		tprintf("%#lx, ", tcp->u_arg[0]);
-		if (printflags(clockflags, tcp->u_arg[1]) == 0)
-			tprintf("0");
+		printflags(clockflags, tcp->u_arg[1], "TIMER_???");
 		tprintf(", ");
 		printitv(tcp, tcp->u_arg[2]);
 		tprintf(", ");
diff --git a/util.c b/util.c
index f54f6fc..d92c0ea 100644
--- a/util.c
+++ b/util.c
@@ -247,7 +247,7 @@
 printxval(xlat, val, dflt)
 const struct xlat *xlat;
 int val;
-char *dflt;
+const char *dflt;
 {
 	char *str = xlookup(xlat, val);
 
@@ -284,9 +284,10 @@
 }
 
 int
-printflags(xlat, flags)
+printflags(xlat, flags, dflt)
 const struct xlat *xlat;
 int flags;
+const char *dflt;
 {
 	int n;
 	char *sep;
@@ -305,10 +306,23 @@
 			n++;
 		}
 	}
-	if (flags) {
-		tprintf("%s%#x", sep, flags);
-		n++;
+
+	if (n) {
+		if (flags) {
+			tprintf("%s%#x", sep, flags);
+			n++;
+		}
+	} else {
+		if (flags) {
+			tprintf("%#x", flags);
+			if (dflt)
+				tprintf(" /* %s */", dflt);
+		} else {
+			if (dflt)
+				tprintf("0");
+		}
 	}
+
 	return n;
 }