blob: ca86200333e4a59a574a134824d1ad60399a301e (
plain)
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
|
#include <sys/socket.h>
#include <sys/uio.h>
#include <string.h>
#define SIZE_OF_T(TYPE) \
do { \
if (0 == strcmp(type, #TYPE)) { \
return sizeof(TYPE); \
} \
} while (0)
#define SIZE_OF_S(TYPE) \
do { \
if (0 == strcmp(type, #TYPE)) { \
return sizeof(struct TYPE); \
} \
} while (0)
size_t
size_of(const char* type) {
// Builtin
SIZE_OF_T(long);
// sys/socket
SIZE_OF_S(sockaddr_storage);
// sys/uio
SIZE_OF_S(iovec);
return 0;
}
|