From mboxrd@z Thu Jan 1 00:00:00 1970 From: Simon Glass Subject: [PATCH 9/9] dtput: Support adding strings with spaces Date: Tue, 5 Jul 2011 12:02:57 -0700 Message-ID: <1309892577-23828-10-git-send-email-sjg@chromium.org> References: <1309892577-23828-1-git-send-email-sjg@chromium.org> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1309892577-23828-1-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: devicetree-discuss-bounces+gldd-devicetree-discuss=m.gmane.org-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org Sender: devicetree-discuss-bounces+gldd-devicetree-discuss=m.gmane.org-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org To: Devicetree Discuss List-Id: devicetree@vger.kernel.org Previously dtput would use sscanf() to read the string from the command line, even if no format string was provided. Thus it would split up words at whitespace boundaries, and put a \0 between each. This changes that behavior. Previously: $ ../dtput dtget-test.dtb -ts /compatible this is a test $ ../dtget dtget-test.dtb /compatible 116 104 105 115 0 105 115 0 97 110 111 116 104 101 114 0 116 101 115 116 0 and you have to use the -ts flag to see this as a list of strings $ ../dtget dtget-test.dtb -ts /compatible this is a test Now: $ ../dtput dtget-test.dtb -ts /compatible "this is another test" $ ../dtget dtget-test.dtb /compatible this is another test this is another test $ ../dtget dtget-test.dtb /compatible -tb 116 104 105 115 32 105 115 32 97 110 111 116 104 101 114 32 116 101 115 116 0 Note that the \0 terminators are gone. Signed-off-by: Simon Glass --- dtput.c | 7 ++++++- tests/run_tests.sh | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/dtput.c b/dtput.c index 48e3c75..d02e6ab 100644 --- a/dtput.c +++ b/dtput.c @@ -55,7 +55,12 @@ static int encode_value(char **arg, int arg_count, const char *format, for (; arg_count > 0; arg++, arg_count--, upto += len) { /* assume integer unless told otherwise */ if (type == 's') { - sscanf(*arg, format ? format : "%s", value); + if (format) + sscanf(*arg, format, value); + else { + strncpy(value, *arg, MAX_VALUE_SIZE - 1); + value[MAX_VALUE_SIZE - 1] = '\0'; + } len = strlen(value) + 1; if (verbose) fprintf(stderr, "\tstring: '%s'\n", value); diff --git a/tests/run_tests.sh b/tests/run_tests.sh index d95d1fe..71cfab3 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -434,10 +434,12 @@ dtput_tests () { file=dtget-test.dtb $DTC -O dtb -o $file ${file%.dtb}.dts 2>/dev/null - # run_dtput_test + # run_dtput_test run_dtput_test "Simple string" "a_model" $file "/model" "a_model" -ts run_dtput_test "Multiple string s" "board1 board2" \ + $file "/compatible" "board1 board2" -ts -f%s + run_dtput_test "Single string with spaces" "board1 board2" \ $file "/compatible" "board1 board2" -ts run_dtput_test "Integer" "32768" $file "/cpus/PowerPC,970@1/d-cache-size" \ "32768" -- 1.7.3.1