Skip to content

Commit

Permalink
utilfdt_read: pass back up the length of data read
Browse files Browse the repository at this point in the history
For a follow up commit, we want to be able to scan the buffer that was
returned to us.  In order to do that safely, we need to know how big
the buffer actually is, so pass that back if requested.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
  • Loading branch information
vapier authored and Jon Loeliger committed Apr 21, 2013
1 parent f8cb5dd commit cc2c178
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion fdtget.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ static int do_fdtget(struct display_info *disp, const char *filename,
const char *prop;
int i, node;

blob = utilfdt_read(filename);
blob = utilfdt_read(filename, NULL);
if (!blob)
return -1;

Expand Down
2 changes: 1 addition & 1 deletion fdtput.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ static int do_fdtput(struct display_info *disp, const char *filename,
char *blob;
int len, ret = 0;

blob = utilfdt_read(filename);
blob = utilfdt_read(filename, NULL);
if (!blob)
return -1;

Expand Down
2 changes: 1 addition & 1 deletion tests/testutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ int nodename_eq(const char *s1, const char *s2)
void *load_blob(const char *filename)
{
char *blob;
int ret = utilfdt_read_err(filename, &blob);
int ret = utilfdt_read_err(filename, &blob, NULL);

if (ret)
CONFIG("Couldn't open blob from \"%s\": %s", filename,
Expand Down
8 changes: 5 additions & 3 deletions util.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ char get_escape_char(const char *s, int *i)
return val;
}

int utilfdt_read_err(const char *filename, char **buffp)
int utilfdt_read_err(const char *filename, char **buffp, off_t *len)
{
int fd = 0; /* assume stdin */
char *buf = NULL;
Expand Down Expand Up @@ -238,13 +238,15 @@ int utilfdt_read_err(const char *filename, char **buffp)
free(buf);
else
*buffp = buf;
if (len)
*len = bufsize;
return ret;
}

char *utilfdt_read(const char *filename)
char *utilfdt_read(const char *filename, off_t *len)
{
char *buff;
int ret = utilfdt_read_err(filename, &buff);
int ret = utilfdt_read_err(filename, &buff, len);

if (ret) {
fprintf(stderr, "Couldn't open blob from '%s': %s\n", filename,
Expand Down
6 changes: 4 additions & 2 deletions util.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,10 @@ char get_escape_char(const char *s, int *i);
* stderr.
*
* @param filename The filename to read, or - for stdin
* @param len If non-NULL, the amount of data we managed to read
* @return Pointer to allocated buffer containing fdt, or NULL on error
*/
char *utilfdt_read(const char *filename);
char *utilfdt_read(const char *filename, off_t *len);

/**
* Read a device tree file into a buffer. Does not report errors, but only
Expand All @@ -91,9 +92,10 @@ char *utilfdt_read(const char *filename);
*
* @param filename The filename to read, or - for stdin
* @param buffp Returns pointer to buffer containing fdt
* @param len If non-NULL, the amount of data we managed to read
* @return 0 if ok, else an errno value representing the error
*/
int utilfdt_read_err(const char *filename, char **buffp);
int utilfdt_read_err(const char *filename, char **buffp, off_t *len);


/**
Expand Down

0 comments on commit cc2c178

Please sign in to comment.