Simplify format specifiers for uintmax_t
This commit is contained in:
		@@ -5,8 +5,8 @@
 | 
				
			|||||||
#include "../util.h"
 | 
					#include "../util.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined(__linux__)
 | 
					#if defined(__linux__)
 | 
				
			||||||
	#include <inttypes.h>
 | 
					 | 
				
			||||||
	#include <limits.h>
 | 
						#include <limits.h>
 | 
				
			||||||
 | 
						#include <stdint.h>
 | 
				
			||||||
	#include <unistd.h>
 | 
						#include <unistd.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	static const char *
 | 
						static const char *
 | 
				
			||||||
@@ -93,7 +93,7 @@
 | 
				
			|||||||
		if (!pick(bat, "/sys/class/power_supply/%s/charge_now",
 | 
							if (!pick(bat, "/sys/class/power_supply/%s/charge_now",
 | 
				
			||||||
		          "/sys/class/power_supply/%s/energy_now",
 | 
							          "/sys/class/power_supply/%s/energy_now",
 | 
				
			||||||
		          path, sizeof(path)) ||
 | 
							          path, sizeof(path)) ||
 | 
				
			||||||
		    pscanf(path, "%" PRIuMAX, &charge_now) < 0) {
 | 
							    pscanf(path, "%ju", &charge_now) < 0) {
 | 
				
			||||||
			return NULL;
 | 
								return NULL;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -101,7 +101,7 @@
 | 
				
			|||||||
			if (!pick(bat, "/sys/class/power_supply/%s/current_now",
 | 
								if (!pick(bat, "/sys/class/power_supply/%s/current_now",
 | 
				
			||||||
			          "/sys/class/power_supply/%s/power_now", path,
 | 
								          "/sys/class/power_supply/%s/power_now", path,
 | 
				
			||||||
			          sizeof(path)) ||
 | 
								          sizeof(path)) ||
 | 
				
			||||||
			    pscanf(path, "%" PRIuMAX, ¤t_now) < 0) {
 | 
								    pscanf(path, "%ju", ¤t_now) < 0) {
 | 
				
			||||||
				return NULL;
 | 
									return NULL;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -113,7 +113,7 @@
 | 
				
			|||||||
			h = timeleft;
 | 
								h = timeleft;
 | 
				
			||||||
			m = (timeleft - (double)h) * 60;
 | 
								m = (timeleft - (double)h) * 60;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			return bprintf("%" PRIuMAX "h %" PRIuMAX "m", h, m);
 | 
								return bprintf("%juh %jum", h, m);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		return "";
 | 
							return "";
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,13 +1,11 @@
 | 
				
			|||||||
/* See LICENSE file for copyright and license details. */
 | 
					/* See LICENSE file for copyright and license details. */
 | 
				
			||||||
 | 
					#include <stdint.h>
 | 
				
			||||||
#include <stdio.h>
 | 
					#include <stdio.h>
 | 
				
			||||||
#include <string.h>
 | 
					#include <string.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "../util.h"
 | 
					#include "../util.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined(__linux__)
 | 
					#if defined(__linux__)
 | 
				
			||||||
	#include <inttypes.h>
 | 
					 | 
				
			||||||
	#include <stdint.h>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	const char *
 | 
						const char *
 | 
				
			||||||
	cpu_freq(void)
 | 
						cpu_freq(void)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
@@ -15,7 +13,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		/* in kHz */
 | 
							/* in kHz */
 | 
				
			||||||
		if (pscanf("/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq",
 | 
							if (pscanf("/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq",
 | 
				
			||||||
		            "%" PRIuMAX, &freq) != 1) {
 | 
							            "%ju", &freq) != 1) {
 | 
				
			||||||
			return NULL;
 | 
								return NULL;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -45,7 +43,6 @@
 | 
				
			|||||||
		                (a[0] + a[1] + a[2] + a[3] + a[4] + a[5] + a[6]))));
 | 
							                (a[0] + a[1] + a[2] + a[3] + a[4] + a[5] + a[6]))));
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
#elif defined(__OpenBSD__)
 | 
					#elif defined(__OpenBSD__)
 | 
				
			||||||
	#include <inttypes.h>
 | 
					 | 
				
			||||||
	#include <sys/param.h>
 | 
						#include <sys/param.h>
 | 
				
			||||||
	#include <sys/sched.h>
 | 
						#include <sys/sched.h>
 | 
				
			||||||
	#include <sys/sysctl.h>
 | 
						#include <sys/sysctl.h>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,6 @@
 | 
				
			|||||||
/* See LICENSE file for copyright and license details. */
 | 
					/* See LICENSE file for copyright and license details. */
 | 
				
			||||||
#if defined(__linux__)
 | 
					#if defined(__linux__)
 | 
				
			||||||
	#include <inttypes.h>
 | 
						#include <stdint.h>
 | 
				
			||||||
	#include <stdio.h>
 | 
						#include <stdio.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	#include "../util.h"
 | 
						#include "../util.h"
 | 
				
			||||||
@@ -11,11 +11,11 @@
 | 
				
			|||||||
		uintmax_t num;
 | 
							uintmax_t num;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (pscanf("/proc/sys/kernel/random/entropy_avail",
 | 
							if (pscanf("/proc/sys/kernel/random/entropy_avail",
 | 
				
			||||||
		           "%" PRIuMAX, &num) != 1) {
 | 
							           "%ju", &num) != 1) {
 | 
				
			||||||
			return NULL;
 | 
								return NULL;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		return bprintf("%" PRIuMAX, num);
 | 
							return bprintf("%ju", num);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
#elif defined(__OpenBSD__)
 | 
					#elif defined(__OpenBSD__)
 | 
				
			||||||
	const char *
 | 
						const char *
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,7 +5,7 @@
 | 
				
			|||||||
#include "../util.h"
 | 
					#include "../util.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined(__linux__)
 | 
					#if defined(__linux__)
 | 
				
			||||||
	#include <inttypes.h>
 | 
						#include <stdint.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const char *
 | 
						const char *
 | 
				
			||||||
	netspeed_rx(const char *interface)
 | 
						netspeed_rx(const char *interface)
 | 
				
			||||||
@@ -22,7 +22,7 @@
 | 
				
			|||||||
		              interface) < 0) {
 | 
							              interface) < 0) {
 | 
				
			||||||
			return NULL;
 | 
								return NULL;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if (pscanf(path, "%" PRIuMAX, &rxbytes) != 1) {
 | 
							if (pscanf(path, "%ju", &rxbytes) != 1) {
 | 
				
			||||||
			return NULL;
 | 
								return NULL;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if (oldrxbytes == 0) {
 | 
							if (oldrxbytes == 0) {
 | 
				
			||||||
@@ -48,7 +48,7 @@
 | 
				
			|||||||
		              interface) < 0) {
 | 
							              interface) < 0) {
 | 
				
			||||||
			return NULL;
 | 
								return NULL;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if (pscanf(path, "%" PRIuMAX, &txbytes) != 1) {
 | 
							if (pscanf(path, "%ju", &txbytes) != 1) {
 | 
				
			||||||
			return NULL;
 | 
								return NULL;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if (oldtxbytes == 0) {
 | 
							if (oldtxbytes == 0) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,7 +4,7 @@
 | 
				
			|||||||
#include "../util.h"
 | 
					#include "../util.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined(__linux__)
 | 
					#if defined(__linux__)
 | 
				
			||||||
	#include <inttypes.h>
 | 
						#include <stdint.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const char *
 | 
						const char *
 | 
				
			||||||
	ram_free(void)
 | 
						ram_free(void)
 | 
				
			||||||
@@ -12,9 +12,9 @@
 | 
				
			|||||||
		uintmax_t free;
 | 
							uintmax_t free;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (pscanf("/proc/meminfo",
 | 
							if (pscanf("/proc/meminfo",
 | 
				
			||||||
		           "MemTotal: %" PRIuMAX " kB\n"
 | 
							           "MemTotal: %ju kB\n"
 | 
				
			||||||
		           "MemFree: %" PRIuMAX " kB\n"
 | 
							           "MemFree: %ju kB\n"
 | 
				
			||||||
		           "MemAvailable: %" PRIuMAX " kB\n",
 | 
							           "MemAvailable: %ju kB\n",
 | 
				
			||||||
		           &free, &free, &free) != 3) {
 | 
							           &free, &free, &free) != 3) {
 | 
				
			||||||
			return NULL;
 | 
								return NULL;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -28,10 +28,10 @@
 | 
				
			|||||||
		uintmax_t total, free, buffers, cached;
 | 
							uintmax_t total, free, buffers, cached;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (pscanf("/proc/meminfo",
 | 
							if (pscanf("/proc/meminfo",
 | 
				
			||||||
		           "MemTotal: %" PRIuMAX " kB\n"
 | 
							           "MemTotal: %ju kB\n"
 | 
				
			||||||
		           "MemFree: %" PRIuMAX " kB\n"
 | 
							           "MemFree: %ju kB\n"
 | 
				
			||||||
		           "MemAvailable: %" PRIuMAX " kB\nBuffers: %ld kB\n"
 | 
							           "MemAvailable: %ju kB\nBuffers: %ju kB\n"
 | 
				
			||||||
		           "Cached: %" PRIuMAX " kB\n",
 | 
							           "Cached: %ju kB\n",
 | 
				
			||||||
		           &total, &free, &buffers, &buffers, &cached) != 5) {
 | 
							           &total, &free, &buffers, &buffers, &cached) != 5) {
 | 
				
			||||||
			return NULL;
 | 
								return NULL;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -49,7 +49,7 @@
 | 
				
			|||||||
	{
 | 
						{
 | 
				
			||||||
		uintmax_t total;
 | 
							uintmax_t total;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (pscanf("/proc/meminfo", "MemTotal: %" PRIuMAX " kB\n",
 | 
							if (pscanf("/proc/meminfo", "MemTotal: %ju kB\n",
 | 
				
			||||||
		           &total) != 1) {
 | 
							           &total) != 1) {
 | 
				
			||||||
			return NULL;
 | 
								return NULL;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -63,10 +63,10 @@
 | 
				
			|||||||
		uintmax_t total, free, buffers, cached;
 | 
							uintmax_t total, free, buffers, cached;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (pscanf("/proc/meminfo",
 | 
							if (pscanf("/proc/meminfo",
 | 
				
			||||||
		           "MemTotal: %" PRIuMAX " kB\n"
 | 
							           "MemTotal: %ju kB\n"
 | 
				
			||||||
		           "MemFree: %" PRIuMAX " kB\n"
 | 
							           "MemFree: %ju kB\n"
 | 
				
			||||||
		           "MemAvailable: %" PRIuMAX " kB\nBuffers: %" PRIuMAX " kB\n"
 | 
							           "MemAvailable: %ju kB\nBuffers: %ju kB\n"
 | 
				
			||||||
		           "Cached: %" PRIuMAX " kB\n",
 | 
							           "Cached: %ju kB\n",
 | 
				
			||||||
		           &total, &free, &buffers, &buffers, &cached) != 5) {
 | 
							           &total, &free, &buffers, &buffers, &cached) != 5) {
 | 
				
			||||||
			return NULL;
 | 
								return NULL;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,18 +4,18 @@
 | 
				
			|||||||
#include "../util.h"
 | 
					#include "../util.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined(__linux__)
 | 
					#if defined(__linux__)
 | 
				
			||||||
	#include <inttypes.h>
 | 
						#include <stdint.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const char *
 | 
						const char *
 | 
				
			||||||
	temp(const char *file)
 | 
						temp(const char *file)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		uintmax_t temp;
 | 
							uintmax_t temp;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if(pscanf(file, "%" PRIuMAX, &temp) != 1) {
 | 
							if(pscanf(file, "%ju", &temp) != 1) {
 | 
				
			||||||
			return NULL;
 | 
								return NULL;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		return bprintf("%" PRIuMAX, temp / 1000);
 | 
							return bprintf("%ju", temp / 1000);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
#elif defined(__OpenBSD__)
 | 
					#elif defined(__OpenBSD__)
 | 
				
			||||||
	#include <stdio.h>
 | 
						#include <stdio.h>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
/* See LICENSE file for copyright and license details. */
 | 
					/* See LICENSE file for copyright and license details. */
 | 
				
			||||||
#include <inttypes.h>
 | 
					#include <stdint.h>
 | 
				
			||||||
#include <stdio.h>
 | 
					#include <stdio.h>
 | 
				
			||||||
#include <time.h>
 | 
					#include <time.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -19,5 +19,5 @@ uptime(void)
 | 
				
			|||||||
	h = uptime.tv_sec / 3600;
 | 
						h = uptime.tv_sec / 3600;
 | 
				
			||||||
	m = uptime.tv_sec % 3600 / 60;
 | 
						m = uptime.tv_sec % 3600 / 60;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return bprintf("%" PRIuMAX "h %" PRIuMAX "m", h, m);
 | 
						return bprintf("%juh %jum", h, m);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user