Page MenuHomeFreeBSD

b64encode: implement -w to wrap lines
ClosedPublic

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

Details

Summary

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

Lint
Lint Skipped
Unit
Unit Tests Skipped

Event Timeline

pstef requested review of this revision.Nov 11 2021, 5:26 PM
pstef created this revision.
delphij added inline comments.
usr.bin/uuencode/uuencode.c
107

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...

174

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?

268

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!

usr.bin/uuencode/uuencode.c
107

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.

174

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

268

Good point, I'll use optarg_long here.

Address mistakes, describe the magic buffer length.

Minor style nit, otherwise looks fine.

usr.bin/uuencode/uuencode.c
253–254

style

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.