tools/lib/subcmd/subcmd-util.h

Source file repositories/reference/linux-study-clean/tools/lib/subcmd/subcmd-util.h

File Facts

System
Linux kernel
Corpus path
tools/lib/subcmd/subcmd-util.h
Extension
.h
Size
1678 bytes
Lines
76
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: implementation source
Status
source implementation candidate

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

if ((nr) > alloc) { \
			if (alloc_nr(alloc) < (nr)) \
				alloc = (nr); \
			else \
				alloc = alloc_nr(alloc); \
			x = xrealloc((x), alloc * sizeof(*(x))); \
		} \
	} while(0)

static inline void *xrealloc(void *ptr, size_t size)
{
	void *ret = realloc(ptr, size);
	if (!ret)
		die("Out of memory, realloc failed");
	return ret;
}

#define astrcatf(out, fmt, ...)						\
({									\
	char *tmp = *(out);						\
	if (asprintf((out), "%s" fmt, tmp ?: "", ## __VA_ARGS__) == -1)	\
		die("asprintf failed");					\
	free(tmp);							\
})

static inline void astrcat(char **out, const char *add)
{
	char *tmp = *out;

	if (asprintf(out, "%s%s", tmp ?: "", add) == -1)
		die("asprintf failed");

	free(tmp);
}

#endif /* __SUBCMD_UTIL_H */

Annotation

Implementation Notes