X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=include%2Fvsprintf.h;h=d9fb68add0c9ac70e2423a2e855aa5ef6920e412;hb=2493ce6258a59881b702cbe255db9e53f1e3fd13;hp=2ac41d1923069bcda08fd5cba4bb8067899a3f32;hpb=aaf5e825606a70ddc8fca8e366d8c16a6fd3cc7c;p=platform%2Fkernel%2Fu-boot.git diff --git a/include/vsprintf.h b/include/vsprintf.h index 2ac41d1..d9fb68a 100644 --- a/include/vsprintf.h +++ b/include/vsprintf.h @@ -1,13 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ /* * (C) Copyright 2000-2009 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. - * - * SPDX-License-Identifier: GPL-2.0+ */ #ifndef __VSPRINTF_H #define __VSPRINTF_H +#include +#include + ulong simple_strtoul(const char *cp, char **endp, unsigned int base); /** @@ -39,10 +41,59 @@ int strict_strtoul(const char *cp, unsigned int base, unsigned long *res); unsigned long long simple_strtoull(const char *cp, char **endp, unsigned int base); long simple_strtol(const char *cp, char **endp, unsigned int base); + +/** + * trailing_strtol() - extract a trailing integer from a string + * + * Given a string this finds a trailing number on the string and returns it. + * For example, "abc123" would return 123. + * + * @str: String to exxamine + * @return training number if found, else -1 + */ +long trailing_strtol(const char *str); + +/** + * trailing_strtoln() - extract a trailing integer from a fixed-length string + * + * Given a fixed-length string this finds a trailing number on the string + * and returns it. For example, "abc123" would return 123. Only the + * characters between @str and @end - 1 are examined. If @end is NULL, it is + * set to str + strlen(str). + * + * @str: String to exxamine + * @end: Pointer to end of string to examine, or NULL to use the + * whole string + * @return training number if found, else -1 + */ +long trailing_strtoln(const char *str, const char *end); + +/** + * panic() - Print a message and reset/hang + * + * Prints a message on the console(s) and then resets. If CONFIG_PANIC_HANG is + * defined, then it will hang instead of resetting. + * + * @param fmt: printf() format string for message, which should not include + * \n, followed by arguments + */ void panic(const char *fmt, ...) __attribute__ ((format (__printf__, 1, 2), noreturn)); /** + * panic_str() - Print a message and reset/hang + * + * Prints a message on the console(s) and then resets. If CONFIG_PANIC_HANG is + * defined, then it will hang instead of resetting. + * + * This function can be used instead of panic() when your board does not + * already use printf(), * to keep code size small. + * + * @param fmt: string to display, which should not include \n + */ +void panic_str(const char *str) __attribute__ ((noreturn)); + +/** * Format a string and place it in a buffer * * @param buf The buffer to place the result into @@ -61,12 +112,10 @@ int sprintf(char *buf, const char *fmt, ...) * Format a string and place it in a buffer (va_list version) * * @param buf The buffer to place the result into - * @param size The size of the buffer, including the trailing null space * @param fmt The format string to use * @param args Arguments for the format string * @return the number of characters which have been written into - * the @buf not including the trailing '\0'. If @size is == 0 the function - * returns 0. + * the @buf not including the trailing '\0'. * * If you're not already dealing with a va_list consider using scnprintf(). * @@ -75,7 +124,6 @@ int sprintf(char *buf, const char *fmt, ...) int vsprintf(char *buf, const char *fmt, va_list args); char *simple_itoa(ulong i); -#ifdef CONFIG_SYS_VSNPRINTF /** * Format a string and place it in a buffer * @@ -150,17 +198,6 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args); * See the vsprintf() documentation for format string extensions over C99. */ int vscnprintf(char *buf, size_t size, const char *fmt, va_list args); -#else -/* - * Use macros to silently drop the size parameter. Note that the 'cn' - * versions are the same as the 'n' versions since the functions assume - * there is always enough buffer space when !CONFIG_SYS_VSNPRINTF - */ -#define snprintf(buf, size, fmt, args...) sprintf(buf, fmt, ##args) -#define scnprintf(buf, size, fmt, args...) sprintf(buf, fmt, ##args) -#define vsnprintf(buf, size, fmt, args...) vsprintf(buf, fmt, ##args) -#define vscnprintf(buf, size, fmt, args...) vsprintf(buf, fmt, ##args) -#endif /* CONFIG_SYS_VSNPRINTF */ /** * print_grouped_ull() - print a value with digits grouped by ',' @@ -173,4 +210,28 @@ int vscnprintf(char *buf, size_t size, const char *fmt, va_list args); */ void print_grouped_ull(unsigned long long int_val, int digits); +bool str2off(const char *p, loff_t *num); +bool str2long(const char *p, ulong *num); + +/** + * strmhz() - Convert a value to a Hz string + * + * This creates a string indicating the number of MHz of a value. For example, + * 2700000 produces "2.7". + * @buf: Buffer to hold output string, which must be large enough + * @hz: Value to convert + */ +char *strmhz(char *buf, unsigned long hz); + +/** + * str_to_upper() - Convert a string to upper case + * + * This simply uses toupper() on each character of the string. + * + * @in: String to convert (must be large enough to hold the output string) + * @out: Buffer to put converted string + * @len: Number of bytes available in @out (SIZE_MAX for all) + */ +void str_to_upper(const char *in, char *out, size_t len); + #endif