]> git.ipfire.org Git - thirdparty/kernel/linux.git/blame - tools/perf/trace/beauty/socket_type.c
License cleanup: add SPDX GPL-2.0 license identifier to files with no license
[thirdparty/kernel/linux.git] / tools / perf / trace / beauty / socket_type.c
CommitLineData
b2441318 1// SPDX-License-Identifier: GPL-2.0
bbf86c43
ACM
2#include <sys/types.h>
3#include <sys/socket.h>
4
5#ifndef SOCK_DCCP
6# define SOCK_DCCP 6
7#endif
8
9#ifndef SOCK_CLOEXEC
10# define SOCK_CLOEXEC 02000000
11#endif
12
13#ifndef SOCK_NONBLOCK
14# define SOCK_NONBLOCK 00004000
15#endif
16
17#ifndef SOCK_TYPE_MASK
18#define SOCK_TYPE_MASK 0xf
19#endif
20
21static size_t syscall_arg__scnprintf_socket_type(char *bf, size_t size, struct syscall_arg *arg)
22{
23 size_t printed;
24 int type = arg->val,
25 flags = type & ~SOCK_TYPE_MASK;
26
27 type &= SOCK_TYPE_MASK;
28 /*
29 * Can't use a strarray, MIPS may override for ABI reasons.
30 */
31 switch (type) {
32#define P_SK_TYPE(n) case SOCK_##n: printed = scnprintf(bf, size, #n); break;
33 P_SK_TYPE(STREAM);
34 P_SK_TYPE(DGRAM);
35 P_SK_TYPE(RAW);
36 P_SK_TYPE(RDM);
37 P_SK_TYPE(SEQPACKET);
38 P_SK_TYPE(DCCP);
39 P_SK_TYPE(PACKET);
40#undef P_SK_TYPE
41 default:
42 printed = scnprintf(bf, size, "%#x", type);
43 }
44
45#define P_SK_FLAG(n) \
46 if (flags & SOCK_##n) { \
47 printed += scnprintf(bf + printed, size - printed, "|%s", #n); \
48 flags &= ~SOCK_##n; \
49 }
50
51 P_SK_FLAG(CLOEXEC);
52 P_SK_FLAG(NONBLOCK);
53#undef P_SK_FLAG
54
55 if (flags)
56 printed += scnprintf(bf + printed, size - printed, "|%#x", flags);
57
58 return printed;
59}
60
61#define SCA_SK_TYPE syscall_arg__scnprintf_socket_type