[Toybox] New toy: mknod
Rob Landley
rob at landley.net
Thu Feb 16 20:10:07 PST 2012
On 02/13/2012 01:12 PM, Elie De Brauwer wrote:
> Hi all,
>
> In attachment you can find a new version of mknod. Two small comments:
> 1. mknod uses this awkward non-getopt-like syntax (you know mknod
> /dev/null c 1 3) for now I'm using optargs for all of them with a limit
> stating the number of arguments should be between 2 and 4. If anybody
> could point into ways in which the argument parsing could be more
> helpful that would be appreciated.
I get Monday off from work and hope to catch up and everything then.
Alas, until then, I'm totally swamped...
> 2. mknod typically has support for passing the mode with -m, I haven't
> added this (yet) (and if you want it just chmod it afterwards, oh, right
> chmod isn't there yet either), but I think that it might be worth to
> extend argument passing in lib/args.c for reading modes, at least chmod
> would already benefit from that too.
Yeah, I've been pondering that. I thought about blogging this, but if I
did I can't find it. (November 27, 2011 entry says I was poking at
this, but I didn't post details. The closest is the cryptic remark at
the end of http://landley.net/toybox/todos/susv4.txt that says "-m
mode": that was my not to self to work on this.)
In addition to mknod and chmod, mkdir and mkfifo needed this too
according to the spec. (You'd think touch and truncate would, but no...)
The fiddly thing is not burdening commands that don't need it with the
size of the function. It definitely needs to be a library function, but
if I have it in lib/args.c it doesn't conditionally drop out based on
whether or not it's used by any of the selected commands (the optimizer
can't see into the contents of the optstrings we're parsing), and it
might be big enough that we actually want that...
Also, it raised the idea that I might want to teach lib/args.c to to
parse globals from non-option arguments. I.E. some way to tell it
"mknod -m u+x" and "chmod u+x" both become a gobal automatically. I
wound up poking at that a bit and then backing it out again as more
complexity than it was worth. (I wound up writing lib_args
documentation instead...)
This sort of design work is the time consuming stuff. Doing is easy in
comparison to figuring out _what_ to do...
Rob
More information about the Toybox
mailing list