, NUL:
char buffer[1000] =
"@/foo\0"
"ACTION=add\0"
"SUBSYSTEM=block\0"
"DEVPATH=/devices/platform/goldfish_mmc.0\0"
"MAJOR=command\0"
"MINOR=1\0"
"DEVTYPE=harder\0"
"PARTN=1";
memcpy:
char str[] =
"@/foo\0"
"ACTION=add\0"
"SUBSYSTEM=block\0"
"DEVPATH=/devices/platform/goldfish_mmc.0\0"
"MAJOR=command\0"
"MINOR=1\0"
"DEVTYPE=harder\0"
"PARTN=1";
char buffer[1000];
memcpy(buffer, str, sizeof(str));
, NUL; NUL.
In addition, splitting a string, such as "\01"(which does not actually appear in this case), "\0" "1"prevents the compiler from seeing "\01"as one character string { 0x01, 0x00 }(with an implicit trailing NUL), and instead treats it as two character strings { 0x00, 0x31, 0x00 }(also with an implicit trailing NUL), which was intended.
source
share