chiark / gitweb /
random-util: always cast from smaller to bigger type when comparing
[elogind.git] / src / basic / format-util.h
1 #pragma once
2
3 /***
4   This file is part of systemd.
5
6   Copyright 2015 Ronny Chevalier
7
8   systemd is free software; you can redistribute it and/or modify it
9   under the terms of the GNU Lesser General Public License as published by
10   the Free Software Foundation; either version 2.1 of the License, or
11   (at your option) any later version.
12
13   systemd is distributed in the hope that it will be useful, but
14   WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16   Lesser General Public License for more details.
17
18   You should have received a copy of the GNU Lesser General Public License
19   along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 ***/
21
22 #include <inttypes.h>
23
24 #if SIZEOF_PID_T == 4
25 #  define PID_PRI PRIi32
26 #elif SIZEOF_PID_T == 2
27 #  define PID_PRI PRIi16
28 #else
29 #  error Unknown pid_t size
30 #endif
31 #define PID_FMT "%" PID_PRI
32
33 #if SIZEOF_UID_T == 4
34 #  define UID_FMT "%" PRIu32
35 #elif SIZEOF_UID_T == 2
36 #  define UID_FMT "%" PRIu16
37 #else
38 #  error Unknown uid_t size
39 #endif
40
41 #if SIZEOF_GID_T == 4
42 #  define GID_FMT "%" PRIu32
43 #elif SIZEOF_GID_T == 2
44 #  define GID_FMT "%" PRIu16
45 #else
46 #  error Unknown gid_t size
47 #endif
48
49 #if SIZEOF_TIME_T == 8
50 #  define PRI_TIME PRIi64
51 #elif SIZEOF_TIME_T == 4
52 #  define PRI_TIME "li"
53 #else
54 #  error Unknown time_t size
55 #endif
56
57 #if defined __x86_64__ && defined __ILP32__
58 #  define PRI_TIMEX PRIi64
59 #else
60 #  define PRI_TIMEX "li"
61 #endif
62
63 #if SIZEOF_RLIM_T == 8
64 #  define RLIM_FMT "%" PRIu64
65 #elif SIZEOF_RLIM_T == 4
66 #  define RLIM_FMT "%" PRIu32
67 #else
68 #  error Unknown rlim_t size
69 #endif
70
71 #if SIZEOF_DEV_T == 8
72 #  define DEV_FMT "%" PRIu64
73 #elif SIZEOF_DEV_T == 4
74 #  define DEV_FMT "%" PRIu32
75 #else
76 #  error Unknown dev_t size
77 #endif
78
79 #if SIZEOF_INO_T == 8
80 #  define INO_FMT "%" PRIu64
81 #elif SIZEOF_INO_T == 4
82 #  define INO_FMT "%" PRIu32
83 #else
84 #  error Unknown ino_t size
85 #endif