2017-11-18 17:09:20 +01:00
|
|
|
/* SPDX-License-Identifier: LGPL-2.1+ */
|
2012-07-18 19:07:51 +02:00
|
|
|
#pragma once
|
2010-04-21 03:27:44 +02:00
|
|
|
|
2015-11-30 21:43:37 +01:00
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
#include "hashmap.h"
|
|
|
|
#include "macro.h"
|
2015-12-01 23:22:03 +01:00
|
|
|
#include "set.h"
|
2012-12-22 19:28:19 +01:00
|
|
|
|
2010-04-21 03:27:44 +02:00
|
|
|
typedef struct FDSet FDSet;
|
|
|
|
|
|
|
|
FDSet* fdset_new(void);
|
2015-01-06 00:26:25 +01:00
|
|
|
FDSet* fdset_free(FDSet *s);
|
2010-04-21 03:27:44 +02:00
|
|
|
|
|
|
|
int fdset_put(FDSet *s, int fd);
|
|
|
|
int fdset_put_dup(FDSet *s, int fd);
|
|
|
|
|
|
|
|
bool fdset_contains(FDSet *s, int fd);
|
|
|
|
int fdset_remove(FDSet *s, int fd);
|
|
|
|
|
tree-wide: be more careful with the type of array sizes
Previously we were a bit sloppy with the index and size types of arrays,
we'd regularly use unsigned. While I don't think this ever resulted in
real issues I think we should be more careful there and follow a
stricter regime: unless there's a strong reason not to use size_t for
array sizes and indexes, size_t it should be. Any allocations we do
ultimately will use size_t anyway, and converting forth and back between
unsigned and size_t will always be a source of problems.
Note that on 32bit machines "unsigned" and "size_t" are equivalent, and
on 64bit machines our arrays shouldn't grow that large anyway, and if
they do we have a problem, however that kind of overly large allocation
we have protections for usually, but for overflows we do not have that
so much, hence let's add it.
So yeah, it's a story of the current code being already "good enough",
but I think some extra type hygiene is better.
This patch tries to be comprehensive, but it probably isn't and I missed
a few cases. But I guess we can cover that later as we notice it. Among
smaller fixes, this changes:
1. strv_length()' return type becomes size_t
2. the unit file changes array size becomes size_t
3. DNS answer and query array sizes become size_t
Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=76745
2018-04-27 14:09:31 +02:00
|
|
|
int fdset_new_array(FDSet **ret, const int *fds, size_t n_fds);
|
2015-01-06 00:26:25 +01:00
|
|
|
int fdset_new_fill(FDSet **ret);
|
|
|
|
int fdset_new_listen_fds(FDSet **ret, bool unset);
|
2010-04-21 03:27:44 +02:00
|
|
|
|
|
|
|
int fdset_cloexec(FDSet *fds, bool b);
|
2012-12-22 19:28:19 +01:00
|
|
|
|
|
|
|
int fdset_close_others(FDSet *fds);
|
|
|
|
|
|
|
|
unsigned fdset_size(FDSet *fds);
|
2015-01-06 00:26:25 +01:00
|
|
|
bool fdset_isempty(FDSet *fds);
|
2012-12-22 19:28:19 +01:00
|
|
|
|
|
|
|
int fdset_iterate(FDSet *s, Iterator *i);
|
|
|
|
|
2015-01-06 00:26:25 +01:00
|
|
|
int fdset_steal_first(FDSet *fds);
|
|
|
|
|
2019-03-22 15:22:45 +01:00
|
|
|
void fdset_close(FDSet *fds);
|
|
|
|
|
2012-12-22 19:28:19 +01:00
|
|
|
#define FDSET_FOREACH(fd, fds, i) \
|
|
|
|
for ((i) = ITERATOR_FIRST, (fd) = fdset_iterate((fds), &(i)); (fd) >= 0; (fd) = fdset_iterate((fds), &(i)))
|
2013-10-12 01:33:48 +02:00
|
|
|
|
2013-10-14 04:59:26 +02:00
|
|
|
DEFINE_TRIVIAL_CLEANUP_FUNC(FDSet*, fdset_free);
|
2013-10-12 01:33:48 +02:00
|
|
|
#define _cleanup_fdset_free_ _cleanup_(fdset_freep)
|