[openib-general] [PATCH] diags: eliminate __WORDSIZE ifdefs for printing

Sasha Khapyorsky sashak at voltaire.com
Wed Dec 27 15:10:17 PST 2006


Use portable PRIx64 macro in printf format strings instead of using
'#if __WORDSIZE == 64' with printf style functions.

Signed-off-by: Sasha Khapyorsky <sashak at voltaire.com>
---
 diags/src/ibnetdiscover.c |   63 +++++--------------------------------
 diags/src/ibroute.c       |   15 ++-------
 diags/src/ibtracert.c     |   74 +++++----------------------------------------
 diags/src/sminfo.c        |    8 +----
 4 files changed, 22 insertions(+), 138 deletions(-)

diff --git a/diags/src/ibnetdiscover.c b/diags/src/ibnetdiscover.c
index 31b7063..0b5078b 100644
--- a/diags/src/ibnetdiscover.c
+++ b/diags/src/ibnetdiscover.c
@@ -213,21 +213,12 @@ dump_endnode(ib_portid_t *path, char *prompt, Node *node, Port *port)
 	if (!dumplevel)
 		return;
 
-#if __WORDSIZE == 64
-	fprintf(f, "%s -> %s %s {%016lx} portnum %d lid %d-%d\"%s\"\n",
+	fprintf(f, "%s -> %s %s {%016" PRIx64 "} portnum %d lid %d-%d\"%s\"\n",
 		portid2str(path), prompt,
 		(node->type <= IB_NODE_MAX ? node_type_str[node->type] : "???"),
 		node->nodeguid, node->type == SWITCH_NODE ? 0 : port->portnum,
 		port->lid, port->lid + (1 << port->lmc) - 1,
 		clean_nodedesc(node->nodedesc));
-#else
-	fprintf(f, "%s -> %s %s {%016Lx} portnum %d lid %d-%d\"%s\"\n",
-		portid2str(path), prompt,
-		(node->type <= IB_NODE_MAX ? node_type_str[node->type] : "???"),
-		node->nodeguid, node->type == SWITCH_NODE ? 0 : port->portnum,
-		port->lid, port->lid + (1 << port->lmc) - 1,
-		clean_nodedesc(node->nodedesc));
-#endif
 }
 
 #define HASHGUID(guid)		((uint32_t)(((uint32_t)(guid) * 101) ^ ((uint32_t)((guid) >> 32) * 103)))
@@ -265,11 +256,7 @@ link_port(Port *port, Node *node, Port *remoteport)
 		}
 
 	if (dumplevel)
-#if __WORDSIZE == 64
-		fprintf(f, "\t[%d] {%016lx}\n", port->portnum, port->portguid);
-#else
-		fprintf(f, "\t[%d] {%016Lx}\n", port->portnum, port->portguid);
-#endif
+		fprintf(f, "\t[%d] {%016" PRIx64 "}\n", port->portnum, port->portguid);
 
 	DEBUG("inserting new port %p (%d) to node %p", port, port->portnum, node);
 	port->node = node;
@@ -447,13 +434,8 @@ node_name(Node *node)
 {
 	static char buf[256];
 
-#if __WORDSIZE == 64
-	sprintf(buf, "\"%s-%016lx\"",
+	sprintf(buf, "\"%s-%016" PRIx64 "\"",
 		node->type == SWITCH_NODE ? "S" : "H", node->nodeguid);
-#else
-	sprintf(buf, "\"%s-%016Lx\"",
-		node->type == SWITCH_NODE ? "S" : "H", node->nodeguid);
-#endif
 
 	return buf;
 }
@@ -477,17 +459,10 @@ list_node(Node *node)
 		node_type = "???";
 		break;
 	}
-#if __WORDSIZE == 64
-	fprintf(f, "%s\t : 0x%016lx ports %d devid 0x%x vendid 0x%x \"%s\"\n",
-		node_type,
-		node->nodeguid, node->numports, node->devid, node->vendid,
-		clean_nodedesc(node->nodedesc));
-#else
-	fprintf(f, "%s\t : 0x%016Lx ports %d devid 0x%x vendid 0x%x \"%s\"\n",
+	fprintf(f, "%s\t : 0x%016" PRIx64 " ports %d devid 0x%x vendid 0x%x \"%s\"\n",
 		node_type,
 		node->nodeguid, node->numports, node->devid, node->vendid,
 		clean_nodedesc(node->nodedesc));
-#endif
 }
 
 void
@@ -495,11 +470,7 @@ out_ids(Node *node)
 {
 	fprintf(f, "\nvendid=0x%x\ndevid=0x%x\n", node->vendid, node->devid);
 	if (node->sysimgguid)
-#if __WORDSIZE == 64
-		fprintf(f, "sysimgguid=0x%lx\n", node->sysimgguid);
-#else
-		fprintf(f, "sysimgguid=0x%Lx\n", node->sysimgguid);
-#endif
+		fprintf(f, "sysimgguid=0x%" PRIx64 "\n", node->sysimgguid);
 }
 
 void
@@ -514,11 +485,7 @@ out_chassis(Node *node)
 	fprintf(f, "\nChassis %d", node->chrecord->chassisnum);
 	guid = get_chassis_guid(node->chrecord->chassisnum);
 	if (guid) {
-#if __WORDSIZE == 64
-		fprintf(f, " (guid 0x%lx)", guid);
-#else
-		fprintf(f, " (guid 0x%Lx)", guid);
-#endif
+		fprintf(f, " (guid 0x%" PRIx64 ")", guid);
 	}
 	fprintf(f, "\n");
 }
@@ -541,11 +508,7 @@ out_switch(Node *node, int group)
 	}
 
 	out_ids(node);
-#if __WORDSIZE == 64
-	fprintf(f, "%s=0x%lx", "switchguid", node->nodeguid);
-#else
-	fprintf(f, "%s=0x%Lx", "switchguid", node->nodeguid);
-#endif
+	fprintf(f, "switchguid=0x%" PRIx64, node->nodeguid);
 	if (group) {
 		if (node->chrecord) {
 			if (node->chrecord->chassisnum) {
@@ -592,11 +555,7 @@ out_ca(Node *node)
 		node_type2 = "???";
 		break;
 	}
-#if __WORDSIZE == 64
-	fprintf(f, "%s%s=0x%lx\n", node_type, "guid", node->nodeguid);
-#else
-	fprintf(f, "%s%s=0x%Lx\n", node_type, "guid", node->nodeguid);
-#endif
+	fprintf(f, "%sguid=0x%" PRIx64 "\n", node_type, node->nodeguid);
 	fprintf(f, "%s\t%d %s\t\t# %s\n",
 		node_type2, node->numports, node_name(node),
 		clean_nodedesc(node->nodedesc));
@@ -649,11 +608,7 @@ dump_topology(int listtype, int group)
 	if (!listtype) {
 		fprintf(f, "#\n# Topology file: generated on %s#\n", ctime(&t));
 		fprintf(f, "# Max of %d hops discovered\n", maxhops_discovered);
-#if __WORDSIZE == 64
-		fprintf(f, "# Initiated from node %016lx port %016lx\n", mynode->nodeguid, mynode->portguid);
-#else
-		fprintf(f, "# Initiated from node %016Lx port %016Lx\n", mynode->nodeguid, mynode->portguid);
-#endif
+		fprintf(f, "# Initiated from node %016" PRIx64 " port %016" PRIx64 "\n", mynode->nodeguid, mynode->portguid);
 	}
 
 	/* Make pass on switches */
diff --git a/diags/src/ibroute.c b/diags/src/ibroute.c
index f590fdd..8152b6d 100644
--- a/diags/src/ibroute.c
+++ b/diags/src/ibroute.c
@@ -41,6 +41,7 @@
 #include <stdarg.h>
 #include <time.h>
 #include <string.h>
+#include <inttypes.h>
 #include <getopt.h>
 #include <netinet/in.h>
 
@@ -192,13 +193,8 @@ dump_multicast_tables(ib_portid_t *portid, int startlid, int endlid)
 		endlid = IB_MAX_MCAST_LID;
 	}
 
-#if __WORDSIZE == 64
-	printf("Multicast mlids [0x%x-0x%x] of switch %s guid 0x%016lx (%s):\n",
+	printf("Multicast mlids [0x%x-0x%x] of switch %s guid 0x%016" PRIx64 " (%s):\n",
 		startlid, endlid, portid2str(portid), nodeguid, nd);
-#else
-	printf("Multicast mlids [0x%x-0x%x] of switch %s guid 0x%016Lx (%s):\n",
-		startlid, endlid, portid2str(portid), nodeguid, nd);
-#endif
 
 	if (brief)
 		printf(" MLid       Port Mask\n");
@@ -338,13 +334,8 @@ dump_unicast_tables(ib_portid_t *portid, int startlid, int endlid)
 		endlid = IB_MAX_UCAST_LID;
 	}
 
-#if __WORDSIZE == 64
-	printf("Unicast lids [0x%x-0x%x] of switch %s guid 0x%016lx (%s):\n",
-		startlid, endlid, portid2str(portid), nodeguid, nd);
-#else
-	printf("Unicast lids [0x%x-0x%x] of switch %s guid 0x%016Lx (%s):\n",
+	printf("Unicast lids [0x%x-0x%x] of switch %s guid 0x%016" PRIx64 " (%s):\n",
 		startlid, endlid, portid2str(portid), nodeguid, nd);
-#endif
 	DEBUG("Switch top is 0x%x\n", top);
 
 	printf("  Lid  Out   Destination\n");
diff --git a/diags/src/ibtracert.c b/diags/src/ibtracert.c
index bfa3d25..e545e9a 100644
--- a/diags/src/ibtracert.c
+++ b/diags/src/ibtracert.c
@@ -214,32 +214,17 @@ dump_endnode(int dump, char *prompt, Node *node, Port *port)
 	if (!dump)
 		return;
 	if (dump == 1) {
-#if __WORDSIZE == 64
-		fprintf(f, "%s {%016lx}[%d]\n",
+		fprintf(f, "%s {%016" PRIx64 "}[%d]\n",
 			prompt, node->nodeguid,
 			node->type == IB_NODE_SWITCH ? 0 : port->portnum);
-#else
-		fprintf(f, "%s {%016Lx}[%d]\n",
-			prompt, node->nodeguid,
-			node->type == IB_NODE_SWITCH ? 0 : port->portnum);
-#endif
 		return;
 	}
-#if __WORDSIZE == 64
-	fprintf(f, "%s %s {%016lx} portnum %d lid 0x%x-0x%x \"%s\"\n",
-		prompt,
-		(node->type <= IB_NODE_MAX ? node_type_str[node->type] : "???"),
-		node->nodeguid, node->type == IB_NODE_SWITCH ? 0 : port->portnum,
-		port->lid, port->lid + (1 << port->lmc) - 1,
-		node->nodedesc);
-#else
-	fprintf(f, "%s %s {%016Lx} portnum %d lid 0x%x-0x%x \"%s\"\n",
+	fprintf(f, "%s %s {%016" PRIx64 "} portnum %d lid 0x%x-0x%x \"%s\"\n",
 		prompt,
 		(node->type <= IB_NODE_MAX ? node_type_str[node->type] : "???"),
 		node->nodeguid, node->type == IB_NODE_SWITCH ? 0 : port->portnum,
 		port->lid, port->lid + (1 << port->lmc) - 1,
 		node->nodedesc);
-#endif
 }
 
 static void
@@ -247,29 +232,16 @@ dump_route(int dump, Node *node, int outport, Port *port)
 {
 	if (!dump && !verbose)
 		return;
-#if __WORDSIZE == 64
 	if (dump == 1)
-		fprintf(f, "[%d] -> {%016lx}[%d]\n",
+		fprintf(f, "[%d] -> {%016" PRIx64 "}[%d]\n",
 			outport, port->portguid, port->portnum);
 	else
-		fprintf(f, "[%d] -> %s port {%016lx}[%d] lid 0x%x-0x%x \"%s\"\n",
+		fprintf(f, "[%d] -> %s port {%016" PRIx64 "}[%d] lid 0x%x-0x%x \"%s\"\n",
 			outport,
 			(node->type <= IB_NODE_MAX ? node_type_str[node->type] : "???"),
 			port->portguid, port->portnum,
 			port->lid, port->lid + (1 << port->lmc) - 1,
 			node->nodedesc);
-#else
-	if (dump == 1)
-		fprintf(f, "[%d] -> {%016Lx}[%d]\n",
-			outport, port->portguid, port->portnum);
-	else
-		fprintf(f, "[%d] -> %s port {%016Lx}[%d] lid 0x%x-0x%x \"%s\"\n",
-			outport,
-			(node->type <= IB_NODE_MAX ? node_type_str[node->type] : "???"),
-			port->portguid, port->portnum,
-			port->lid, port->lid + (1 << port->lmc) - 1,
-			node->nodedesc);
-#endif
 }
 
 static int
@@ -667,65 +639,35 @@ dump_mcpath(Node *node, int dumplevel)
 		dump_mcpath(node->upnode, dumplevel);
 
 	if (!node->dist) {
-#if __WORDSIZE == 64
-		printf("From %s 0x%lx port %d lid 0x%x-0x%x \"%s\"\n",
-			(node->type <= IB_NODE_MAX ? node_type_str[node->type] : "???"),
-			node->nodeguid, node->ports->portnum, node->ports->lid,
-			node->ports->lid + (1 << node->ports->lmc) - 1,
-			node->nodedesc);
-#else
-		printf("From %s 0x%Lx port %d lid 0x%x-0x%x \"%s\"\n",
+		printf("From %s 0x%" PRIx64 " port %d lid 0x%x-0x%x \"%s\"\n",
 			(node->type <= IB_NODE_MAX ? node_type_str[node->type] : "???"),
 			node->nodeguid, node->ports->portnum, node->ports->lid,
 			node->ports->lid + (1 << node->ports->lmc) - 1,
 			node->nodedesc);
-#endif
 		return;
 	}
 
 	if (node->dist) {
-#if __WORDSIZE == 64
 		if (dumplevel == 1)
-			printf("[%d] -> %s {%016lx}[%d]\n",
+			printf("[%d] -> %s {%016" PRIx64 "}[%d]\n",
 				node->ports->remoteport->portnum,
 				(node->type <= IB_NODE_MAX ? node_type_str[node->type] : "???"),
 				node->nodeguid, node->upport);
 		else
-			printf("[%d] -> %s 0x%lx[%d] lid 0x%x \"%s\"\n",
+			printf("[%d] -> %s 0x%" PRIx64 "[%d] lid 0x%x \"%s\"\n",
 				node->ports->remoteport->portnum,
 				(node->type <= IB_NODE_MAX ? node_type_str[node->type] : "???"),
 				node->nodeguid, node->upport,
 				node->ports->lid, node->nodedesc);
-#else
-		if (dumplevel == 1)
-			printf("[%d] -> %s {%016Lx}[%d]\n",
-				node->ports->remoteport->portnum,
-				(node->type <= IB_NODE_MAX ? node_type_str[node->type] : "???"),
-				node->nodeguid, node->upport);
-		else
-			printf("[%d] -> %s 0x%Lx[%d] lid 0x%x \"%s\"\n",
-				node->ports->remoteport->portnum,
-				(node->type <= IB_NODE_MAX ? node_type_str[node->type] : "???"),
-				node->nodeguid, node->upport,
-				node->ports->lid, node->nodedesc);
-#endif
 	}
 
 	if (node->dist < 0)
 	/* target node */
-#if __WORDSIZE == 64
-		printf("To %s 0x%lx port %d lid 0x%x-0x%x \"%s\"\n",
+		printf("To %s 0x%" PRIx64 " port %d lid 0x%x-0x%x \"%s\"\n",
 			(node->type <= IB_NODE_MAX ? node_type_str[node->type] : "???"),
 			node->nodeguid, node->ports->portnum, node->ports->lid,
 			node->ports->lid + (1 << node->ports->lmc) - 1,
 			node->nodedesc);
-#else
-		printf("To %s 0x%Lx port %d lid 0x%x-0x%x \"%s\"\n",
-			(node->type <= IB_NODE_MAX ? node_type_str[node->type] : "???"),
-			node->nodeguid, node->ports->portnum, node->ports->lid,
-			node->ports->lid + (1 << node->ports->lmc) - 1,
-			node->nodedesc);
-#endif
 }
 
 static void
diff --git a/diags/src/sminfo.c b/diags/src/sminfo.c
index 98e2ed7..c01f195 100644
--- a/diags/src/sminfo.c
+++ b/diags/src/sminfo.c
@@ -39,6 +39,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <stdarg.h>
+#include <inttypes.h>
 #include <getopt.h>
 
 #define __BUILD_VERSION_TAG__ 1.1
@@ -218,13 +219,8 @@ main(int argc, char **argv)
 	mad_decode_field(sminfo, IB_SMINFO_PRIO_F, &prio);
 	mad_decode_field(sminfo, IB_SMINFO_STATE_F, &state);
 
-#if __WORDSIZE == 64
-	printf("sminfo: sm lid %d sm guid 0x%lx, activity count %d priority %d state %d %s\n",
+	printf("sminfo: sm lid %d sm guid 0x%" PRIx64 ", activity count %d priority %d state %d %s\n",
 		portid.lid, guid, act, prio, state, STATESTR(state));
-#else
-	printf("sminfo: sm lid %d sm guid 0x%Lx, activity count %d priority %d state %d %s\n",
-		portid.lid, guid, act, prio, state, STATESTR(state));
-#endif
 
 	exit(0);
 }
-- 
1.4.4.2.gfc82d





More information about the general mailing list