libpayload: minor cleanups
Apply some const correctness to const/non-const strings in libc and libpci (what an ugly cast that was). Remove duplicated NULL test in printf_putstr(), already done in print_string() - reduces size of libpayload by a few bytes. Change-Id: I13f479df13e39d79cab291e9d99d153e1ef43eae Signed-off-by: Mathias Krause <minipli@googlemail.com> Reviewed-on: http://review.coreboot.org/849 Tested-by: build bot (Jenkins) Reviewed-by: Marc Jones <marcj303@gmail.com>
This commit is contained in:
parent
f17789c4ff
commit
67997d330d
|
@ -85,8 +85,8 @@ typedef enum {
|
||||||
PrintfQualifierPointer,
|
PrintfQualifierPointer,
|
||||||
} qualifier_t;
|
} qualifier_t;
|
||||||
|
|
||||||
static char digits_small[] = "0123456789abcdef";
|
static const char digits_small[] = "0123456789abcdef";
|
||||||
static char digits_big[] = "0123456789ABCDEF";
|
static const char digits_big[] = "0123456789ABCDEF";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Print one or more characters without adding newline.
|
* Print one or more characters without adding newline.
|
||||||
|
@ -109,18 +109,9 @@ static int printf_putnchars(const char *buf, size_t count,
|
||||||
* @param ps Write function specification and support data.
|
* @param ps Write function specification and support data.
|
||||||
* @return Number of characters printed.
|
* @return Number of characters printed.
|
||||||
*/
|
*/
|
||||||
static int printf_putstr(const char *str, struct printf_spec *ps)
|
static inline int printf_putstr(const char *str, struct printf_spec *ps)
|
||||||
{
|
{
|
||||||
size_t count;
|
return printf_putnchars(str, strlen(str), ps);
|
||||||
|
|
||||||
if (str == NULL) {
|
|
||||||
const char *nullstr = "(NULL)";
|
|
||||||
return printf_putnchars(nullstr, strlen(nullstr), ps);
|
|
||||||
}
|
|
||||||
|
|
||||||
count = strlen(str);
|
|
||||||
|
|
||||||
return ps->write((void *)str, count, ps->data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -228,7 +219,7 @@ static int print_string(char *s, int width, unsigned int precision,
|
||||||
static int print_number(uint64_t num, int width, int precision, int base,
|
static int print_number(uint64_t num, int width, int precision, int base,
|
||||||
uint64_t flags, struct printf_spec *ps)
|
uint64_t flags, struct printf_spec *ps)
|
||||||
{
|
{
|
||||||
char *digits = digits_small;
|
const char *digits = digits_small;
|
||||||
char d[PRINT_NUMBER_BUFFER_SIZE];
|
char d[PRINT_NUMBER_BUFFER_SIZE];
|
||||||
char *ptr = &d[PRINT_NUMBER_BUFFER_SIZE - 1];
|
char *ptr = &d[PRINT_NUMBER_BUFFER_SIZE - 1];
|
||||||
int size = 0; /* Size of number with all prefixes and signs. */
|
int size = 0; /* Size of number with all prefixes and signs. */
|
||||||
|
|
|
@ -96,7 +96,7 @@ void pci_filter_init(struct pci_access* pacc, struct pci_filter* pf)
|
||||||
pf->device = -1;
|
pf->device = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *invalid_pci_device_string = (char *)"invalid pci device string";
|
static char invalid_pci_device_string[] = "invalid pci device string";
|
||||||
|
|
||||||
/* parse domain:bus:dev.func (with all components but "dev" optional)
|
/* parse domain:bus:dev.func (with all components but "dev" optional)
|
||||||
* into filter.
|
* into filter.
|
||||||
|
|
Loading…
Reference in New Issue