diff --git a/steam-runtime-tools/libc-utils-internal.h b/steam-runtime-tools/libc-utils-internal.h index e236fdde7110f00258fb013066fc075a4e5c2033..4d770cb7f7c1b1604f7088c4a3beb440c52fde3e 100644 --- a/steam-runtime-tools/libc-utils-internal.h +++ b/steam-runtime-tools/libc-utils-internal.h @@ -21,13 +21,23 @@ int steal_fd (int *fdp); void clear_with_free (void *pp); void clear_with_fclose (void *pp); +/* + * autoclear: + * @clear: A function that can clear a variable of the type with this attribute + * + * A type attribute marking a variable to be cleared with the given + * function when it goes out of scope: + * `autoclear(clear_with_fclose) FILE *fh = fopen (...);`. + */ +#define autoclear(clear) __attribute__((__cleanup__(clear))) + /* * autofclose: * * A type attribute marking a `FILE *` variable to be closed with `fclose()` * when it goes out of scope: `autofclose FILE *fh = fopen (...);`. */ -#define autofclose __attribute__((__cleanup__(clear_with_fclose))) +#define autofclose autoclear(clear_with_fclose) /* * autofree: @@ -35,7 +45,7 @@ void clear_with_fclose (void *pp); * A type attribute marking a pointer variable to be freed with `free()` * when it goes out of scope: `autofree char *str = strdup (...);`. */ -#define autofree __attribute__((__cleanup__(clear_with_free))) +#define autofree autoclear(clear_with_free) /* * clear_pointer: