On 05/08/14 23:05, Ashwini Sharma wrote: > Thanks for clearing the usage part of mkpathat() > > regards, > Ashwini > > > On Wed, May 7, 2014 at 10:28 PM, Rob Landley <[email protected] > <mailto:[email protected]>> wrote: > > On 05/07/14 04:52, Ashwini Sharma wrote: > > Hi Rob, list, > > > > __mkpathat()__ function doesn't create the last component in the > given path > > if (flags & 1) == 0, e.g. input path is "a/b/c" and flags = 2, > then __a__ > > and __b__ are created but __c__ isn't. > > That's right. If you have a path to a directory and want to create the > entire thing, use flags = 3. > > If you have a path to a file and just want to create the directory > leading > up to that file (or confirm it exists and is a directory), use flags > = 2. > > If you want to use it as just "mkdir", flags = 1. > > Then add the verbose flag if you want it to say what it's doing.
Flags like that are always a little tricky. On the one hand, it's compact and flexible. On the other, magic constants are bad. I'm having that problem right now with the comma_collect() infrastructure I'm trying to add to dd (for conv=). It's also needed by mount, and there's something similar in umount already, so in theory it's a good opportunity for code sharing. But the problem is that _using_ it really wants something like: #define COMMALIST "error\0trunc\0fsync\0sync\0swab32\0swab\0" #define COMMA_ERROR 1 #define COMMA_TRUNC 2 #define COMMA_FSYNC 4 #define COMMA_SYNC 8 #define COMMA_SWAB32 16 #define COMMA_SWAP 32 Which isn't necessarily an improvement to doing a non-automated version by hand. For the command line option parsing lib/args.c is doing, I added automatic infrastructure to calculate FLAG_ macross to the build and generate headers, so worrying about bit values isn't the user's problem. For mkpathat() I just documented the bits in a comment before the function and left combining them to the user, because there are only 3 bits to worry about. But in between, neither approach is particularly appealing... Rob _______________________________________________ Toybox mailing list [email protected] http://lists.landley.net/listinfo.cgi/toybox-landley.net
