In need to craft a string with the following format and place it into a single buffer[1000]. Note that \x00 is the null terminator.
@/foo\x00ACTION=add\x00SUBSYSTEM=block\x00DEVPATH=/devices/platform/goldfish_mmc.0\x00MAJOR=command\x00MINOR=1\x00DEVTYPE=harder\x00PARTN=1
So in essence I need to pack following null terminated strings into a single buffer
@/foo
ACTION=add
SUBSYSTEM=block
DEVPATH=/devices/platform/goldfish_mmc.0
MAJOR=command
MINOR=1
DEVTYPE=harder
PARTN=1
How might I go about doing this?
You'll need to copy each string in one at a time, keeping track of where the last copy stopped and starting just after that for the next one.
char *p = buffer;
strcpy(p, "@/foo");
p += strlen(p) + 1;
strcpy(p, "ACTION=add");
p += strlen(p) + 1;
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With