Skip to content
Draft
36 changes: 29 additions & 7 deletions lib/attr.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,49 @@
#endif


#if (__GNUC__ >= 10)
# define MAYBE_UNUSED [[gnu::unused]]
# define NORETURN [[gnu::__noreturn__]]
# define format_attr(type, fmt, va) [[gnu::format(type, fmt, va)]]
# define ATTR_ACCESS(...) [[gnu::access(__VA_ARGS__)]]
# define ATTR_ALLOC_SIZE(...) [[gnu::alloc_size(__VA_ARGS__)]]
#if __has_c_attribute(maybe_unused)
# define MAYBE_UNUSED [[maybe_unused]]
#else
# define MAYBE_UNUSED
#endif

#if __has_c_attribute(noreturn)
# define NORETURN [[noreturn]]
#else
# define NORETURN
#endif

#if __has_c_attribute(gnu::format)
# define format_attr(type, fmt, va) [[gnu::format(type, fmt, va)]]
#else
# define format_attr(type, fmt, va)
#endif

#if __has_c_attribute(gnu::access)
# define ATTR_ACCESS(...) [[gnu::access(__VA_ARGS__)]]
#else
# define ATTR_ACCESS(...)
#endif

#if __has_c_attribute(gnu::alloc_size)
# define ATTR_ALLOC_SIZE(...) [[gnu::alloc_size(__VA_ARGS__)]]
#else
# define ATTR_ALLOC_SIZE(...)
#endif

#if __has_c_attribute(gnu::copy)
# define ATTR_COPY(x) [[gnu::copy(x)]]
#else
# define ATTR_COPY(x)
#endif

#if (__GNUC__ >= 11) && !defined(__clang__)
# define ATTR_MALLOC(deallocator) [[gnu::malloc(deallocator)]]
#else
# define ATTR_MALLOC(deallocator)
#endif

#if (__GNUC__ >= 14)
#if __has_c_attribute(gnu::null_terminated_string_arg)
# define ATTR_STRING(i) [[gnu::null_terminated_string_arg(i)]]
#else
# define ATTR_STRING(i)
Expand Down
10 changes: 6 additions & 4 deletions lib/commonio.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
#define COMMONIO_H


#include <config.h>

#include <stdio.h>

#include "attr.h"
#include "defines.h" /* bool */

Expand Down Expand Up @@ -64,10 +68,8 @@ struct commonio_ops {
* fgets and fputs (can be replaced by versions that
* understand line continuation conventions).
*/
ATTR_ACCESS(write_only, 1, 2)
/*@null@*/char *(*cio_fgets)(/*@returned@*/char *restrict s, int n,
FILE *restrict stream);
int (*cio_fputs)(const char *, FILE *);
ATTR_COPY(fgets) typeof(fgets) *cio_fgets;
ATTR_COPY(fputs) typeof(fputs) *cio_fputs;

/*
* open_hook and close_hook.
Expand Down
20 changes: 13 additions & 7 deletions src/get_subid_owners.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <stdio.h>

#include "atoi/getnum.h"
#include "attr.h"
#include "prototypes.h"
#include "shadowlog.h"
#include "stdlib.h"
Expand All @@ -14,13 +15,8 @@
static const char Prog[] = "get_subid_owners";


static void usage(void)
{
fprintf(stderr, "Usage: [-g] %s subuid\n", Prog);
fprintf(stderr, " list uids who own the given subuid\n");
fprintf(stderr, " pass -g to query a subgid\n");
exit(EXIT_FAILURE);
}
NORETURN static void usage(void);


int main(int argc, char *argv[])
{
Expand Down Expand Up @@ -52,3 +48,13 @@ int main(int argc, char *argv[])
free(uids);
return 0;
}


static void
usage(void)
{
fprintf(stderr, "Usage: [-g] %s subuid\n", Prog);
fprintf(stderr, " list uids who own the given subuid\n");
fprintf(stderr, " pass -g to query a subgid\n");
exit(EXIT_FAILURE);
}
21 changes: 14 additions & 7 deletions src/getsubids.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,17 @@
#include <stdlib.h>
#include <string.h>

#include "attr.h"
#include "prototypes.h"
#include "shadowlog.h"
#include "string/strcmp/streq.h"
#include "subid.h"

static const char Prog[] = "getsubids";

static void usage(void)
{
fprintf(stderr, "Usage: %s [-g] user\n", Prog);
fprintf(stderr, " list subuid ranges for user\n");
fprintf(stderr, " pass -g to list subgid ranges\n");
exit(EXIT_FAILURE);
}

NORETURN static void usage(void);


int main(int argc, char *argv[])
{
Expand Down Expand Up @@ -49,3 +46,13 @@ int main(int argc, char *argv[])
subid_free(ranges);
return 0;
}


static void
usage(void)
{
fprintf(stderr, "Usage: %s [-g] user\n", Prog);
fprintf(stderr, " list subuid ranges for user\n");
fprintf(stderr, " pass -g to list subgid ranges\n");
exit(EXIT_FAILURE);
}
Loading