[U-Boot] Rewriting fw_{printenv,getenv} to not use fgets

Stefano Babic sbabic at denx.de
Thu Jun 7 07:16:02 UTC 2018


Hi Alex,

On 06/06/2018 18:33, Alex Kiernan wrote:
> The line length limit that fw_{printenv,setenv} impose (1024
> characters) has tripped me up twice in as many days, so I figured I'd
> rewrite it to use getline as we already have that in tools/.
> 
> But in looking how I structure that change, I've immediately run into
> questions...
> 
> Right now I have a horrid hack that just pulls in ../getline.[ch], but
> I'm thinking I should hoist the build of the environment tools, into
> tools/Makefile from tools/env/Makefile, move getline.c into tools/lib
> and then patch the trivial change in to swap from fgets to getline in
> then.

I do not understand the point: fgets has not such as limit, it simply
pus bytes into a preallocated buffer. And for scripts (the only point
where fgets is called), yes, the buffer is 1024. This is the only place
where fgets() is called.

On the other side, getline allocates the buffer. In our case, we have
couple of <var> <value> , and it looks strange we cannot have this under
control. If you need this, you have very long value for a variable, and
this makes the script hard to read. It is good practise to split the
long assignment in more variables to improve maintainance.

> 
> I'm aware this also gets used as a library, so I'm guessing I need to
> make linking of getline.c conditional somehow.

But getline is part of glibc. Why do you have to copy it ?

> 
> Does that make sense? Or should I be attempting it some other way.
> 

Best regards,
Stefano Babic

-- 
=====================================================================
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de
=====================================================================


More information about the U-Boot mailing list