diff options
| author | Michael Forney <mforney@mforney.org> | 2019-06-07 11:29:01 -0700 |
|---|---|---|
| committer | Henrik Rydberg <rydberg@bitmath.se> | 2020-01-26 15:00:32 +0100 |
| commit | 5a260fa95a5e7cebdd8f9da947c8d8eb244efae0 (patch) | |
| tree | cb6d4cdee41466c790a4ba93ca480d82f942b4b8 /src | |
| parent | 5f9caa26b81155feede6ff71c9b14fa0e8980fbd (diff) | |
Use a macro for `nlongs` so it can be used in constant expression
This way, it can be used to specify the `absbits` array size (in
`mtdev_configure`) without making it a VLA.
VLAs are an optional feature in C11, and in this case we can determine
the array size statically.
This also matches the macros used in libevdev and libinput.
Signed-off-by: Michael Forney <mforney@mforney.org>
Signed-off-by: Henrik Rydberg <rydberg@bitmath.se>
Diffstat (limited to 'src')
| -rw-r--r-- | src/caps.c | 12 |
1 files changed, 4 insertions, 8 deletions
| @@ -32,16 +32,12 @@ static const int SN_COORD = 250; /* coordinate signal-to-noise ratio */ | |||
| 32 | static const int SN_WIDTH = 100; /* width signal-to-noise ratio */ | 32 | static const int SN_WIDTH = 100; /* width signal-to-noise ratio */ |
| 33 | static const int SN_ORIENT = 10; /* orientation signal-to-noise ratio */ | 33 | static const int SN_ORIENT = 10; /* orientation signal-to-noise ratio */ |
| 34 | 34 | ||
| 35 | static const int bits_per_long = 8 * sizeof(long); | 35 | #define LONG_BITS (sizeof(long) * 8) |
| 36 | 36 | #define NLONGS(x) (((x) + LONG_BITS - 1) / LONG_BITS) | |
| 37 | static inline int nlongs(int nbit) | ||
| 38 | { | ||
| 39 | return (nbit + bits_per_long - 1) / bits_per_long; | ||
| 40 | } | ||
| 41 | 37 | ||
| 42 | static inline int getbit(const unsigned long *map, int key) | 38 | static inline int getbit(const unsigned long *map, int key) |
| 43 | { | 39 | { |
| 44 | return (map[key / bits_per_long] >> (key % bits_per_long)) & 0x01; | 40 | return (map[key / LONG_BITS] >> (key % LONG_BITS)) & 0x01; |
| 45 | } | 41 | } |
| 46 | 42 | ||
| 47 | static int getabs(struct input_absinfo *abs, int key, int fd) | 43 | static int getabs(struct input_absinfo *abs, int key, int fd) |
| @@ -106,7 +102,7 @@ static int mtdev_set_slots(struct mtdev *dev, int fd) | |||
| 106 | 102 | ||
| 107 | int mtdev_configure(struct mtdev *dev, int fd) | 103 | int mtdev_configure(struct mtdev *dev, int fd) |
| 108 | { | 104 | { |
| 109 | unsigned long absbits[nlongs(ABS_MAX)]; | 105 | unsigned long absbits[NLONGS(ABS_MAX)]; |
| 110 | int rc, i; | 106 | int rc, i; |
| 111 | 107 | ||
| 112 | SYSCALL(rc = ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(absbits)), absbits)); | 108 | SYSCALL(rc = ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(absbits)), absbits)); |
