diff options
author | 2019-11-13 16:43:52 +0200 | |
---|---|---|
committer | 2019-11-13 16:43:52 +0200 | |
commit | 87c8d8619a5a8eb252d24701c986f5bae17b97ba (patch) | |
tree | 736d49d9988c5776101d5c039a48171eaf4d5ef5 | |
parent | e2fc18ae456593efe2b968d4af1b8ebfe869d807 (diff) | |
download | librin-87c8d8619a5a8eb252d24701c986f5bae17b97ba.tar.gz librin-87c8d8619a5a8eb252d24701c986f5bae17b97ba.tar.bz2 librin-87c8d8619a5a8eb252d24701c986f5bae17b97ba.zip |
diagnostic: simplify tid printing logic.
Signed-off-by: Gediminas Jakutis <gediminas@varciai.lt>
-rw-r--r-- | src/diagnostic/diagnostic.c | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/src/diagnostic/diagnostic.c b/src/diagnostic/diagnostic.c index a5d7149..e7e7645 100644 --- a/src/diagnostic/diagnostic.c +++ b/src/diagnostic/diagnostic.c @@ -31,7 +31,6 @@ static const char default_format[] = "C:F:mn"; static const char valid_format[] = "CFtTn:m"; static struct iostate { - char pidconv[8]; struct timespec start; FILE *err; FILE *warn; @@ -66,14 +65,7 @@ void rin_diag_cleanup(void) void rin_diag_init(void) { - static const char convstr[8] = "%04hx:"; - clock_gettime(RIN_CLOCK_WALL_COUNTER, &state.start); - - if (sizeof(pid_t) == 4) { - memcpy(state.pidconv, convstr, sizeof(convstr)); - } - atexit(rin_diag_cleanup); } @@ -204,7 +196,13 @@ static void __rin_msg(FILE *stream, const char *prefix, const char *func_name, c fprintf(stream, "%s", func_name); break; case 't': - fprintf(stream, state.pidconv, gettid()); + /* gettid returns pid_t, which is a "signed integer type" + * there is no clean way to detect its actual size, + * so promote it to long it, if smaller and print THAT. + * So far we can semi-safely assume it is not going to be + * bigger than 8 hex digits. + */ + fprintf(stream, "%08lx", (long int) gettid()); break; case 'T': if (!gottime) { |