util: add handling for an auto type

Because sometimes it's much easier and more readable, e.g.
 auto eis_device = eis_touchscreen_get_device(...)

Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/373>
This commit is contained in:
Peter Hutterer 2025-11-06 09:07:25 +10:00 committed by Marge Bot
parent 180c9f2890
commit e8994dfe17
2 changed files with 13 additions and 0 deletions

View file

@ -74,6 +74,15 @@ if cc.has_function('memfd_create', prefix: '#define _GNU_SOURCE\n#include <sys/m
config_h.set10('HAVE_MEMFD_CREATE', true)
endif
code = '''
#include <time.h>
void func() { auto foo = gmtime(NULL); foo->tm_sec = 0; }
'''
if cc.compiles(code, name: 'has C23 auto keyword')
config_h.set('HAVE_C23_AUTO', '1')
endif
dep_math = cc.find_library('m', required: false)
dep_epoll = dependency('epoll-shim', required: false)
dep_libxkbcommon = dependency('xkbcommon', required: false)

View file

@ -31,6 +31,10 @@
#include <unistd.h>
#include <stdio.h>
#ifndef HAVE_C23_AUTO
#define auto __auto_type
#endif
#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
#define ARRAY_FOR_EACH(_arr, _elem) \
for (size_t _i = 0; _i < ARRAY_LENGTH(_arr) && (_elem = &_arr[_i]); _i++)