xlat.c: add sprintxval for printing xval to string
* defs.h (sprintxval): New declaration. (sprintxval): New function.
This commit is contained in:
parent
d9175ac5ce
commit
a907f4a126
2
defs.h
2
defs.h
@ -546,6 +546,8 @@ extern int printxval_searchn(const struct xlat *xlat, size_t xlat_size,
|
||||
uint64_t val, const char *dflt);
|
||||
#define printxval_search(xlat__, val__, dflt__) \
|
||||
printxval_searchn(xlat__, ARRAY_SIZE(xlat__), val__, dflt__)
|
||||
extern int sprintxval(char *buf, size_t size, const struct xlat *,
|
||||
unsigned int val, const char *dflt);
|
||||
extern int printargs(struct tcb *);
|
||||
extern int printargs_u(struct tcb *);
|
||||
extern int printargs_d(struct tcb *);
|
||||
|
14
xlat.c
14
xlat.c
@ -94,6 +94,20 @@ printxvals(const uint64_t val, const char *dflt, const struct xlat *xlat, ...)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
sprintxval(char *const buf, const size_t size, const struct xlat *const x,
|
||||
const unsigned int val, const char *const dflt)
|
||||
{
|
||||
const char *const str = xlookup(x, val);
|
||||
|
||||
if (str)
|
||||
return xsnprintf(buf, size, "%s", str);
|
||||
if (dflt)
|
||||
return xsnprintf(buf, size, "%#x /* %s */", val, dflt);
|
||||
|
||||
return xsnprintf(buf, size, "%#x", val);
|
||||
}
|
||||
|
||||
/**
|
||||
* Print entry in sorted struct xlat table, if it is there.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user