From 31d279616927df62272a80094872c61307c16eb5 Mon Sep 17 00:00:00 2001 From: tg Date: Tue, 7 Apr 2009 19:08:25 +0000 Subject: [PATCH] simplify if ((flags & (1 | 2) == 0) || (flags & (1 | 2) == (1 | 2))) to if (!(flags & 1) ^ !(flags & 2)) which works because ! returns 1 or 0, making the ^ an ^^, and because XOR survives NOTting its arguments --- shf.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/shf.c b/shf.c index c50c5ff..2444326 100644 --- a/shf.c +++ b/shf.c @@ -2,7 +2,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.25 2009/03/14 18:12:55 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.26 2009/04/07 19:08:25 tg Exp $"); /* flags to shf_emptybuf() */ #define EB_READSW 0x01 /* about to switch to reading */ @@ -175,8 +175,7 @@ struct shf * shf_sopen(char *buf, int bsize, int sflags, struct shf *shf) { /* can't have a read+write string */ - if (!(sflags & (SHF_RD | SHF_WR)) || - (sflags & (SHF_RD | SHF_WR)) == (SHF_RD | SHF_WR)) + if (!(sflags & SHF_RD) ^ !(sflags & SHF_WR)) internal_errorf("shf_sopen: flags 0x%x", sflags); if (!shf) {