From: Andre Noll <maan@systemlinux.org>
Date: Sat, 4 Jul 2009 14:21:36 +0000 (+0200)
Subject: audioc stat: Make status item mask 64 bits wide.
X-Git-Tag: v0.3.5~34
X-Git-Url: https://git.tuebingen.mpg.de/?a=commitdiff_plain;h=9c0ba673964679ea7544f1de066bd3c58e176861;p=paraslash.git

audioc stat: Make status item mask 64 bits wide.

We already have more than 32 status items.
---

diff --git a/audiod_command.c b/audiod_command.c
index 3467dbe1..fe30b247 100644
--- a/audiod_command.c
+++ b/audiod_command.c
@@ -170,19 +170,20 @@ int com_stat(int fd, __a_unused int argc, __a_unused char **argv)
 {
 	int i, ret;
 	char *buf = NULL;
-	long unsigned mask = ~0LU;
+	uint64_t mask = 0;
+	const uint64_t one = 1;
 
 	if (argc > 1) {
-		mask = 0;
 		for (i = 1; i < argc; i++) {
 			ret = stat_item_valid(argv[i]);
 			if (ret < 0)
 				return ret;
-			mask |= (1 << ret);
+			mask |= (one << ret);
 		}
-	}
-	PARA_INFO_LOG("mask: 0x%lx\n", mask);
-	if (mask & (1 << SI_PLAY_TIME)) {
+	} else
+		mask--; /* set all bits */
+	PARA_INFO_LOG("mask: 0x%llx\n", (long long unsigned)mask);
+	if (mask & (one << SI_PLAY_TIME)) {
 		int slot_num = get_play_time_slot_num();
 		char *ts = get_time_string(slot_num);
 		if (ts) {
@@ -192,7 +193,7 @@ int com_stat(int fd, __a_unused int argc, __a_unused char **argv)
 			free(ts);
 		}
 	}
-	if (mask & (1 << SI_AUDIOD_UPTIME)) {
+	if (mask & (one << SI_AUDIOD_UPTIME)) {
 		char *tmp, *us = uptime_str();
 		tmp = make_message("%s: %s\n",
 			status_item_list[SI_AUDIOD_UPTIME], us);
@@ -202,14 +203,14 @@ int com_stat(int fd, __a_unused int argc, __a_unused char **argv)
 			goto out;
 		free(tmp);
 	}
-	if (mask & (1 << SI_AUDIOD_STATUS)) {
+	if (mask & (one << SI_AUDIOD_STATUS)) {
 		char *s = audiod_status_string();
 		ret = client_write(fd, s);
 		if (ret < 0)
 			goto out;
 		free(s);
 	}
-	if (mask & (1 << SI_DECODER_FLAGS)) {
+	if (mask & (one << SI_DECODER_FLAGS)) {
 		char *df = decoder_flags();
 		ret = client_write(fd, df);
 		if (ret < 0)
@@ -218,7 +219,7 @@ int com_stat(int fd, __a_unused int argc, __a_unused char **argv)
 	}
 	FOR_EACH_STATUS_ITEM(i) {
 		char *tmp, *v;
-		if (!((1 << i) & mask))
+		if (!((one << i) & mask))
 			continue;
 		v = stat_item_values[i];
 		tmp = make_message("%s%s%s", buf? buf: "",
diff --git a/para.h b/para.h
index 7cdc5e07..e4e9a53d 100644
--- a/para.h
+++ b/para.h
@@ -183,7 +183,7 @@ extern const char *status_item_list[];
 int stat_item_valid(const char *item);
 int stat_line_valid(const char *);
 void stat_client_write(const char *msg, int itemnum);
-int stat_client_add(int fd, long unsigned mask);
+int stat_client_add(int fd, uint64_t mask);
 
 __printf_2_3 void para_log(int, const char*, ...);
 
diff --git a/stat.c b/stat.c
index 4ba1b0e8..0306cba4 100644
--- a/stat.c
+++ b/stat.c
@@ -35,7 +35,7 @@ struct stat_client {
 	/** The stat client's file descriptor. */
 	int fd;
 	/** Bitmask of those status items the client is interested in. */
-	long unsigned item_mask;
+	uint64_t item_mask;
 	/** Its entry in the list of stat clients. */
 	struct list_head node;
 };
@@ -68,7 +68,7 @@ static void dump_stat_client_list(void)
  * \return Positive value on success, or -E_TOO_MANY_CLIENTS if
  * the number of connected clients exceeds #MAX_STAT_CLIENTS.
  */
-int stat_client_add(int fd, long unsigned mask)
+int stat_client_add(int fd, uint64_t mask)
 {
 	struct stat_client *new_client;
 
@@ -103,13 +103,14 @@ void stat_client_write(const char *msg, int itemnum)
 {
 	struct stat_client *sc, *tmp;
 	size_t len = strlen(msg);
+	const uint64_t one = 1;
 
 	if (!initialized || !len)
 		return;
 	list_for_each_entry_safe(sc, tmp, &client_list, node) {
 		int fd = sc->fd, ret;
 
-		if (!((1 << itemnum) & sc->item_mask))
+		if (!((one << itemnum) & sc->item_mask))
 			continue;
 		if (write_ok(fd) > 0) {
 			ret = write(fd, msg, len);