mirror of https://gitlab.com/qemu-project/dtc.git
dtc: Simplify asm_emit_string() implementation
Using %.*s format helps making asm_emit_string() not modify its "str" parameter. While at it, constify the "str" parameter of bin_emit_string() and asm_emit_string(), as these function no longer modify it. Signed-off-by: Nicolas Iooss <nicolas.iooss_linux@m4x.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
parent
881012e443
commit
9ffdf60bf4
20
flattree.c
20
flattree.c
|
@ -49,7 +49,7 @@ static struct version_info {
|
||||||
|
|
||||||
struct emitter {
|
struct emitter {
|
||||||
void (*cell)(void *, cell_t);
|
void (*cell)(void *, cell_t);
|
||||||
void (*string)(void *, char *, int);
|
void (*string)(void *, const char *, int);
|
||||||
void (*align)(void *, int);
|
void (*align)(void *, int);
|
||||||
void (*data)(void *, struct data);
|
void (*data)(void *, struct data);
|
||||||
void (*beginnode)(void *, struct label *labels);
|
void (*beginnode)(void *, struct label *labels);
|
||||||
|
@ -64,7 +64,7 @@ static void bin_emit_cell(void *e, cell_t val)
|
||||||
*dtbuf = data_append_cell(*dtbuf, val);
|
*dtbuf = data_append_cell(*dtbuf, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void bin_emit_string(void *e, char *str, int len)
|
static void bin_emit_string(void *e, const char *str, int len)
|
||||||
{
|
{
|
||||||
struct data *dtbuf = e;
|
struct data *dtbuf = e;
|
||||||
|
|
||||||
|
@ -144,22 +144,14 @@ static void asm_emit_cell(void *e, cell_t val)
|
||||||
(val >> 8) & 0xff, val & 0xff);
|
(val >> 8) & 0xff, val & 0xff);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void asm_emit_string(void *e, char *str, int len)
|
static void asm_emit_string(void *e, const char *str, int len)
|
||||||
{
|
{
|
||||||
FILE *f = e;
|
FILE *f = e;
|
||||||
char c = 0;
|
|
||||||
|
|
||||||
if (len != 0) {
|
|
||||||
/* XXX: ewww */
|
|
||||||
c = str[len];
|
|
||||||
str[len] = '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (len != 0)
|
||||||
|
fprintf(f, "\t.string\t\"%.*s\"\n", len, str);
|
||||||
|
else
|
||||||
fprintf(f, "\t.string\t\"%s\"\n", str);
|
fprintf(f, "\t.string\t\"%s\"\n", str);
|
||||||
|
|
||||||
if (len != 0) {
|
|
||||||
str[len] = c;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void asm_emit_align(void *e, int a)
|
static void asm_emit_align(void *e, int a)
|
||||||
|
|
Loading…
Reference in New Issue