-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.h
34 lines (27 loc) · 905 Bytes
/
utils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#ifndef HANDOVER_UTILS_H_INCLUDED
#define HANDOVER_UTILS_H_INCLUDED
#include <stddef.h>
#include <string.h>
#include "handover.h"
static inline HandoverRecord handover_file_find(HandoverPayload *handover, char const *name)
{
for (size_t i = 0; i < handover->count; i++)
{
HandoverRecord record = handover->records[i];
if (record.tag == HANDOVER_FILE)
{
char *filename = (char *)handover + record.file.name;
if (memcmp(filename, name, strlen(filename)) == 0)
{
return record;
}
}
}
return (HandoverRecord){};
}
#define handover_foreach_record(h, r) \
if ((h)->count > 0) \
for (size_t i = 0; \
i < (h)->count && (((r) = (h)->records[i]), 1); \
++i)
#endif