Joel Kitching has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/33525
Change subject: add ctype.h header ......................................................................
add ctype.h header
Sometimes coreboot needs to compile external code (e.g. vboot_reference) using its own set of system header files. When these headers don't line up with C Standard Library, it causes problems.
Create ctype.h header file. Relocate ctype.h functions from string.h into ctype.h. Update source files which call ctype.h functions accordingly.
Note that ctype.h still lacks five functions which are not used in coreboot source: isalnum, isalpha, iscntrl, isgraph, ispunct
BUG=b:124141368 TEST=make clean && make test-abuild BRANCH=none
Change-Id: I31b5e8af49956ec024a392a73c3c9024b9a9c194 Signed-off-by: Joel Kitching kitching@google.com --- M src/console/vtxprintf.c A src/include/ctype.h M src/include/string.h M src/lib/edid.c M src/lib/hexdump.c M src/lib/hexstrtobin.c M src/lib/string.c M src/vendorcode/google/chromeos/vpd_mac.c 8 files changed, 62 insertions(+), 52 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/25/33525/1
diff --git a/src/console/vtxprintf.c b/src/console/vtxprintf.c index c429ac7..01091c8 100644 --- a/src/console/vtxprintf.c +++ b/src/console/vtxprintf.c @@ -16,6 +16,7 @@ */
#include <console/vtxprintf.h> +#include <ctype.h> #include <string.h>
#define call_tx(x) tx_byte(x, data) diff --git a/src/include/ctype.h b/src/include/ctype.h new file mode 100644 index 0000000..b4684af --- /dev/null +++ b/src/include/ctype.h @@ -0,0 +1,56 @@ +#ifndef CTYPE_H +#define CTYPE_H + +static inline int isspace(int c) +{ + switch (c) { + case ' ': case '\f': case '\n': + case '\r': case '\t': case '\v': + return 1; + default: + return 0; + } +} + +static inline int isprint(int c) +{ + return c >= ' ' && c <= '~'; +} + +static inline int isdigit(int c) +{ + return (c >= '0' && c <= '9'); +} + +static inline int isxdigit(int c) +{ + return ((c >= '0' && c <= '9') || + (c >= 'a' && c <= 'f') || + (c >= 'A' && c <= 'F')); +} + +static inline int isupper(int c) +{ + return (c >= 'A' && c <= 'Z'); +} + +static inline int islower(int c) +{ + return (c >= 'a' && c <= 'z'); +} + +static inline int toupper(int c) +{ + if (islower(c)) + c -= 'a'-'A'; + return c; +} + +static inline int tolower(int c) +{ + if (isupper(c)) + c -= 'A'-'a'; + return c; +} + +#endif /* CTYPE_H */ diff --git a/src/include/string.h b/src/include/string.h index d164f32..3024130 100644 --- a/src/include/string.h +++ b/src/include/string.h @@ -50,56 +50,4 @@ */ unsigned int skip_atoi(char **s);
-static inline int isspace(int c) -{ - switch (c) { - case ' ': case '\f': case '\n': - case '\r': case '\t': case '\v': - return 1; - default: - return 0; - } -} - -static inline int isprint(int c) -{ - return c >= ' ' && c <= '~'; -} - -static inline int isdigit(int c) -{ - return (c >= '0' && c <= '9'); -} - -static inline int isxdigit(int c) -{ - return ((c >= '0' && c <= '9') || - (c >= 'a' && c <= 'f') || - (c >= 'A' && c <= 'F')); -} - -static inline int isupper(int c) -{ - return (c >= 'A' && c <= 'Z'); -} - -static inline int islower(int c) -{ - return (c >= 'a' && c <= 'z'); -} - -static inline int toupper(int c) -{ - if (islower(c)) - c -= 'a'-'A'; - return c; -} - -static inline int tolower(int c) -{ - if (isupper(c)) - c -= 'A'-'a'; - return c; -} - #endif /* STRING_H */ diff --git a/src/lib/edid.c b/src/lib/edid.c index 3087172..e2f213c 100644 --- a/src/lib/edid.c +++ b/src/lib/edid.c @@ -31,6 +31,7 @@ #include <assert.h> #include <stddef.h> #include <console/console.h> +#include <ctype.h> #include <stdint.h> #include <string.h> #include <stdlib.h> diff --git a/src/lib/hexdump.c b/src/lib/hexdump.c index ca36dde..1e689e3 100644 --- a/src/lib/hexdump.c +++ b/src/lib/hexdump.c @@ -13,6 +13,7 @@ */
#include <console/console.h> +#include <ctype.h> #include <lib.h> #include <string.h>
diff --git a/src/lib/hexstrtobin.c b/src/lib/hexstrtobin.c index ed2abc4..61290b8 100644 --- a/src/lib/hexstrtobin.c +++ b/src/lib/hexstrtobin.c @@ -11,6 +11,7 @@ * GNU General Public License for more details. */
+#include <ctype.h> #include <lib.h> #include <string.h>
diff --git a/src/lib/string.c b/src/lib/string.c index a19f017..eb6adb6 100644 --- a/src/lib/string.c +++ b/src/lib/string.c @@ -1,4 +1,5 @@ #include <assert.h> +#include <ctype.h> #include <rules.h> #include <string.h> #include <stddef.h> diff --git a/src/vendorcode/google/chromeos/vpd_mac.c b/src/vendorcode/google/chromeos/vpd_mac.c index e3ef04b..fcd3efe 100644 --- a/src/vendorcode/google/chromeos/vpd_mac.c +++ b/src/vendorcode/google/chromeos/vpd_mac.c @@ -15,6 +15,7 @@
#include <boot/coreboot_tables.h> #include <console/console.h> +#include <ctype.h> #include <string.h>
#include <drivers/vpd/vpd.h>
Joel Kitching has uploaded a new patch set (#2). ( https://review.coreboot.org/c/coreboot/+/33525 )
Change subject: add ctype.h header ......................................................................
add ctype.h header
Sometimes coreboot needs to compile external code (e.g. vboot_reference) using its own set of system header files. When these headers don't line up with C Standard Library, it causes problems.
Create ctype.h header file. Relocate ctype.h functions from string.h into ctype.h. Update source files which call ctype.h functions accordingly.
Note that ctype.h still lacks five functions which are not used in coreboot source: isalnum, isalpha, iscntrl, isgraph, ispunct
BUG=b:124141368 TEST=make clean && make test-abuild BRANCH=none
Change-Id: I31b5e8af49956ec024a392a73c3c9024b9a9c194 Signed-off-by: Joel Kitching kitching@google.com --- M src/console/vtxprintf.c A src/include/ctype.h M src/include/string.h M src/lib/device_tree.c M src/lib/edid.c M src/lib/fit.c M src/lib/hexdump.c M src/lib/hexstrtobin.c M src/lib/string.c M src/vendorcode/cavium/bdk/lame_string.c M src/vendorcode/cavium/bdk/libdram/dram-spd.c M src/vendorcode/google/chromeos/vpd_mac.c 12 files changed, 66 insertions(+), 52 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/25/33525/2
Julius Werner has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/33525 )
Change subject: add ctype.h header ......................................................................
Patch Set 2: Code-Review+2
Joel Kitching has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/33525 )
Change subject: add ctype.h header ......................................................................
Patch Set 2:
Gentle ping
Julius Werner has submitted this change and it was merged. ( https://review.coreboot.org/c/coreboot/+/33525 )
Change subject: add ctype.h header ......................................................................
add ctype.h header
Sometimes coreboot needs to compile external code (e.g. vboot_reference) using its own set of system header files. When these headers don't line up with C Standard Library, it causes problems.
Create ctype.h header file. Relocate ctype.h functions from string.h into ctype.h. Update source files which call ctype.h functions accordingly.
Note that ctype.h still lacks five functions which are not used in coreboot source: isalnum, isalpha, iscntrl, isgraph, ispunct
BUG=b:124141368 TEST=make clean && make test-abuild BRANCH=none
Change-Id: I31b5e8af49956ec024a392a73c3c9024b9a9c194 Signed-off-by: Joel Kitching kitching@google.com Reviewed-on: https://review.coreboot.org/c/coreboot/+/33525 Tested-by: build bot (Jenkins) no-reply@coreboot.org Reviewed-by: Julius Werner jwerner@chromium.org --- M src/console/vtxprintf.c A src/include/ctype.h M src/include/string.h M src/lib/device_tree.c M src/lib/edid.c M src/lib/fit.c M src/lib/hexdump.c M src/lib/hexstrtobin.c M src/lib/string.c M src/vendorcode/cavium/bdk/lame_string.c M src/vendorcode/cavium/bdk/libdram/dram-spd.c M src/vendorcode/google/chromeos/vpd_mac.c 12 files changed, 66 insertions(+), 52 deletions(-)
Approvals: build bot (Jenkins): Verified Julius Werner: Looks good to me, approved
diff --git a/src/console/vtxprintf.c b/src/console/vtxprintf.c index c429ac7..01091c8 100644 --- a/src/console/vtxprintf.c +++ b/src/console/vtxprintf.c @@ -16,6 +16,7 @@ */
#include <console/vtxprintf.h> +#include <ctype.h> #include <string.h>
#define call_tx(x) tx_byte(x, data) diff --git a/src/include/ctype.h b/src/include/ctype.h new file mode 100644 index 0000000..b4684af --- /dev/null +++ b/src/include/ctype.h @@ -0,0 +1,56 @@ +#ifndef CTYPE_H +#define CTYPE_H + +static inline int isspace(int c) +{ + switch (c) { + case ' ': case '\f': case '\n': + case '\r': case '\t': case '\v': + return 1; + default: + return 0; + } +} + +static inline int isprint(int c) +{ + return c >= ' ' && c <= '~'; +} + +static inline int isdigit(int c) +{ + return (c >= '0' && c <= '9'); +} + +static inline int isxdigit(int c) +{ + return ((c >= '0' && c <= '9') || + (c >= 'a' && c <= 'f') || + (c >= 'A' && c <= 'F')); +} + +static inline int isupper(int c) +{ + return (c >= 'A' && c <= 'Z'); +} + +static inline int islower(int c) +{ + return (c >= 'a' && c <= 'z'); +} + +static inline int toupper(int c) +{ + if (islower(c)) + c -= 'a'-'A'; + return c; +} + +static inline int tolower(int c) +{ + if (isupper(c)) + c -= 'A'-'a'; + return c; +} + +#endif /* CTYPE_H */ diff --git a/src/include/string.h b/src/include/string.h index d164f32..3024130 100644 --- a/src/include/string.h +++ b/src/include/string.h @@ -50,56 +50,4 @@ */ unsigned int skip_atoi(char **s);
-static inline int isspace(int c) -{ - switch (c) { - case ' ': case '\f': case '\n': - case '\r': case '\t': case '\v': - return 1; - default: - return 0; - } -} - -static inline int isprint(int c) -{ - return c >= ' ' && c <= '~'; -} - -static inline int isdigit(int c) -{ - return (c >= '0' && c <= '9'); -} - -static inline int isxdigit(int c) -{ - return ((c >= '0' && c <= '9') || - (c >= 'a' && c <= 'f') || - (c >= 'A' && c <= 'F')); -} - -static inline int isupper(int c) -{ - return (c >= 'A' && c <= 'Z'); -} - -static inline int islower(int c) -{ - return (c >= 'a' && c <= 'z'); -} - -static inline int toupper(int c) -{ - if (islower(c)) - c -= 'a'-'A'; - return c; -} - -static inline int tolower(int c) -{ - if (isupper(c)) - c -= 'A'-'a'; - return c; -} - #endif /* STRING_H */ diff --git a/src/lib/device_tree.c b/src/lib/device_tree.c index 2e81a08..b8faab5 100644 --- a/src/lib/device_tree.c +++ b/src/lib/device_tree.c @@ -18,6 +18,7 @@ #include <assert.h> #include <commonlib/stdlib.h> #include <console/console.h> +#include <ctype.h> #include <device_tree.h> #include <endian.h> #include <stdint.h> diff --git a/src/lib/edid.c b/src/lib/edid.c index 3087172..e2f213c 100644 --- a/src/lib/edid.c +++ b/src/lib/edid.c @@ -31,6 +31,7 @@ #include <assert.h> #include <stddef.h> #include <console/console.h> +#include <ctype.h> #include <stdint.h> #include <string.h> #include <stdlib.h> diff --git a/src/lib/fit.c b/src/lib/fit.c index 045f52f..f1052e8 100644 --- a/src/lib/fit.c +++ b/src/lib/fit.c @@ -17,6 +17,7 @@
#include <assert.h> #include <console/console.h> +#include <ctype.h> #include <endian.h> #include <stdint.h> #include <bootmem.h> diff --git a/src/lib/hexdump.c b/src/lib/hexdump.c index ca36dde..1e689e3 100644 --- a/src/lib/hexdump.c +++ b/src/lib/hexdump.c @@ -13,6 +13,7 @@ */
#include <console/console.h> +#include <ctype.h> #include <lib.h> #include <string.h>
diff --git a/src/lib/hexstrtobin.c b/src/lib/hexstrtobin.c index ed2abc4..61290b8 100644 --- a/src/lib/hexstrtobin.c +++ b/src/lib/hexstrtobin.c @@ -11,6 +11,7 @@ * GNU General Public License for more details. */
+#include <ctype.h> #include <lib.h> #include <string.h>
diff --git a/src/lib/string.c b/src/lib/string.c index a19f017..eb6adb6 100644 --- a/src/lib/string.c +++ b/src/lib/string.c @@ -1,4 +1,5 @@ #include <assert.h> +#include <ctype.h> #include <rules.h> #include <string.h> #include <stddef.h> diff --git a/src/vendorcode/cavium/bdk/lame_string.c b/src/vendorcode/cavium/bdk/lame_string.c index 11c5add..3906ca5 100644 --- a/src/vendorcode/cavium/bdk/lame_string.c +++ b/src/vendorcode/cavium/bdk/lame_string.c @@ -11,6 +11,7 @@ */
#include <assert.h> +#include <ctype.h> #include <string.h> #include <lame_string.h>
diff --git a/src/vendorcode/cavium/bdk/libdram/dram-spd.c b/src/vendorcode/cavium/bdk/libdram/dram-spd.c index 1296119..84df69a 100644 --- a/src/vendorcode/cavium/bdk/libdram/dram-spd.c +++ b/src/vendorcode/cavium/bdk/libdram/dram-spd.c @@ -44,6 +44,7 @@ #include <libbdk-hal/bdk-config.h> #include <libbdk-hal/bdk-twsi.h> #include <assert.h> +#include <ctype.h> #include <stdlib.h> #include <string.h>
diff --git a/src/vendorcode/google/chromeos/vpd_mac.c b/src/vendorcode/google/chromeos/vpd_mac.c index e3ef04b..fcd3efe 100644 --- a/src/vendorcode/google/chromeos/vpd_mac.c +++ b/src/vendorcode/google/chromeos/vpd_mac.c @@ -15,6 +15,7 @@
#include <boot/coreboot_tables.h> #include <console/console.h> +#include <ctype.h> #include <string.h>
#include <drivers/vpd/vpd.h>