Page MenuHomeFreeBSD

b64encode: implement -w to wrap lines

Authored by pstef on Nov 11 2021, 5:26 PM.



This functionality is present in GNU base64 and I find it useful when I want to generate random, ASCII-clean data of specific width.

Diff Detail

rG FreeBSD src repository
Automatic diff as part of commit; lint not applicable.
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

pstef requested review of this revision.Nov 11 2021, 5:26 PM
pstef created this revision.
delphij added inline comments.
106 ↗(On Diff #104241)

It looks like the only reason that arg_to_col exists was to parse the -w argument, and what it does was to strtol(), then perform sanity check of the returned value.

Instead of having a separate function, it would make the code more readable to just use strtol() here with the intermediate _long variable to hold the value, then perform the range check of the returned value and give the feedback here, unless there is plan to have the function used in somewhere else...

159 ↗(On Diff #104241)

Mind adding a comment the reasoning of why 1023 was chosen here? If it was rounddown(BUFSIZE, 3), is it possible to represent that way?

254 ↗(On Diff #104241)

Did you mean optarg_long here? (If so, that would be another reason to just fold the function back into the getopt_long loop...)

Hi, thanks for the review!

106 ↗(On Diff #104241)

A previous version of this patch was like what you describe. But then I rewrote the base64 implementation (D32945) and it will use the arg_to_col() too. The other option is to turn this code into a function as part of D32945 and I wanted it to be minimal and clear.

159 ↗(On Diff #104241)

Good point, I'll recall what the idea was and describe it here.

254 ↗(On Diff #104241)

Good point, I'll use optarg_long here.

Address mistakes, describe the magic buffer length.

Minor style nit, otherwise looks fine.

243–244 ↗(On Diff #105059)


This revision is now accepted and ready to land.Apr 16 2022, 5:40 PM
This revision was automatically updated to reflect the committed changes.