aboutsummaryrefslogtreecommitdiffstats
path: root/executor/executor_common.h
blob: 90f731dbfa8df9fd3d26dd009c99b15eaba81359 (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
// Copyright 2025 syzkaller project authors. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.

#ifndef EXECUTOR_COMMON_H
#define EXECUTOR_COMMON_H

#include <stdio.h>
#include <string.h>

static void get_last_opt(const char* cmdline, const char* key, char* out, size_t out_len)
{
	char key_eq[128];
	snprintf(key_eq, sizeof(key_eq), "%s=", key);
	const char* val = NULL;
	for (const char* p = cmdline; (p = strstr(p, key_eq)); p += strlen(key_eq)) {
		if (p == cmdline || p[-1] == ' ' || p[-1] == '\t' || p[-1] == '\n')
			val = p + strlen(key_eq);
	}

	if (val) {
		size_t len = strcspn(val, " \t\n");
		if (len >= out_len)
			len = out_len - 1;
		memcpy(out, val, len);
		out[len] = 0;
	}
}

#endif // EXECUTOR_COMMON_H