
20 Oct
2011
20 Oct
'11
12:46 a.m.
On Wednesday 19 October 2011 18:30:56 Doug Anderson wrote:
--- /dev/null +++ b/common/cmdline.c
+/*
- To run unit tests in this file:
- gcc -DRUN_UNITTESTS -Wall -Werror common/cmdline.c -o cmdline &&
./cmdline
- */
+#ifdef RUN_UNITTESTS
i'm not sure this part should be merged ... better to keep on the back burner while Simon sorts out testing framework with new sandbox arch.
+void add_cmdline_param(char *cmdline, const char *toappend, int bufsize)
bufsize should be size_t
+{
- int cmdline_len = strlen(cmdline);
cmdline_len should be size_t
- if (cmdline_len == 0)
strncat(cmdline, toappend, bufsize-1);
- else {
int bytes_avail = bufsize - cmdline_len;
if (bytes_avail <= 0) {
assert(bytes_avail == 0);
return;
}
cmdline[bufsize-1] = '\0';
cmdline[cmdline_len] = ' ';
strncpy(&cmdline[cmdline_len+1], toappend,
bytes_avail-2);
- }
hmm, i feel like this should be simpler and not need that branch
if (cmdline_len) cmdline[cmdline_len++] = ' '; if (bufsize <= cmdline_len) return; memcpy(&cmdline[cmdline_len], toappend, bufsize - cmdline_len - 1); cmdline[bufsize] = '\0'; -mike