aboutsummaryrefslogtreecommitdiff
path: root/xorg-server/os/utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'xorg-server/os/utils.c')
-rw-r--r--xorg-server/os/utils.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/xorg-server/os/utils.c b/xorg-server/os/utils.c
index 47bc7b5c3..e94179518 100644
--- a/xorg-server/os/utils.c
+++ b/xorg-server/os/utils.c
@@ -204,6 +204,8 @@ int auditTrailLevel = 1;
char *SeatId = NULL;
+sig_atomic_t inSignalContext = FALSE;
+
#ifdef _MSC_VER
static HANDLE s_hSmartScheduleTimer = NULL;
static HANDLE s_hSmartScheduleTimerQueue = NULL;
@@ -1852,3 +1854,47 @@ xstrtokenize(const char *str, const char *separators)
free(list);
return NULL;
}
+
+/* Format a number into a string in a signal safe manner. The string should be
+ * at least 21 characters in order to handle all uint64_t values. */
+void
+FormatUInt64(uint64_t num, char *string)
+{
+ uint64_t divisor;
+ int len;
+ int i;
+
+ for (len = 1, divisor = 10;
+ len < 20 && num / divisor;
+ len++, divisor *= 10);
+
+ for (i = len, divisor = 1; i > 0; i--, divisor *= 10)
+ string[i - 1] = '0' + ((num / divisor) % 10);
+
+ string[len] = '\0';
+}
+
+/* Format a number into a hexadecimal string in a signal safe manner. The string
+ * should be at least 17 characters in order to handle all uint64_t values. */
+void
+FormatUInt64Hex(uint64_t num, char *string)
+{
+ uint64_t divisor;
+ int len;
+ int i;
+
+ for (len = 1, divisor = 0x10;
+ len < 16 && num / divisor;
+ len++, divisor *= 0x10);
+
+ for (i = len, divisor = 1; i > 0; i--, divisor *= 0x10) {
+ int val = (num / divisor) % 0x10;
+
+ if (val < 10)
+ string[i - 1] = '0' + val;
+ else
+ string[i - 1] = 'a' + val - 10;
+ }
+
+ string[len] = '\0';
+}