1 /* $NetBSD: extra-terminating-null.c,v 1.1.1.2 2017/06/08 15:59:26 skrll Exp $ */ 2 3 /* 4 * libfdt - Flat Device Tree manipulation 5 * Testcase for properties with more than one terminating null 6 * Copyright (C) 2009 David Gibson, IBM Corporation. 7 * 8 * This library is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU Lesser General Public License 10 * as published by the Free Software Foundation; either version 2.1 of 11 * the License, or (at your option) any later version. 12 * 13 * This library is distributed in the hope that it will be useful, but 14 * WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * Lesser General Public License for more details. 17 * 18 * You should have received a copy of the GNU Lesser General Public 19 * License along with this library; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 */ 22 #include <stdlib.h> 23 #include <stdio.h> 24 #include <string.h> 25 #include <stdint.h> 26 27 #include <libfdt.h> 28 29 #include "tests.h" 30 #include "testdata.h" 31 32 static void check_extranull(void *fdt, const char *prop, const char *str, int numnulls) 33 { 34 int len = strlen(str); 35 char checkbuf[len+numnulls]; 36 37 memset(checkbuf, 0, sizeof(checkbuf)); 38 memcpy(checkbuf, TEST_STRING_1, len); 39 40 check_getprop(fdt, 0, prop, len+numnulls, checkbuf); 41 } 42 43 int main(int argc, char *argv[]) 44 { 45 void *fdt; 46 47 test_init(argc, argv); 48 49 fdt = load_blob_arg(argc, argv); 50 51 check_extranull(fdt, "extranull0", TEST_STRING_1, 1); 52 check_extranull(fdt, "extranull1,1", TEST_STRING_1, 2); 53 check_extranull(fdt, "extranull1,2", TEST_STRING_1, 2); 54 check_extranull(fdt, "extranull2,1", TEST_STRING_1, 3); 55 check_extranull(fdt, "extranull2,2", TEST_STRING_1, 3); 56 check_extranull(fdt, "extranull2,3", TEST_STRING_1, 3); 57 check_extranull(fdt, "extranull2,4", TEST_STRING_1, 3); 58 59 PASS(); 60 } 61