Jorgen Grahn
3/26/2011 6:37:00 AM
On Sat, 2011-03-26, Why Tea wrote:
> On Saturday, March 26, 2011 11:06:56 AM UTC+11, Barry Schwarz wrote:
>> On Fri, 25 Mar 2011 16:51:21 -0700 (PDT), Why Tea <ytl...@gmail.com>
>> wrote:
>>
>> >When a program receives its command line arguments,
>> >e.g. -abc some_value, is it safe to change "-abc"
>> >to "--abc"? In general, how safe is it to extend an
>> >argv to less than MAX_ARG_STRLEN?
>>
>> Paragraph 5.1.2.2.1-2 guarantees that you can change the value of the
>> 5 bytes in the string "-abc". It does not say anything about the
>> memory that follows the string. It is entirely possible for the "6th
>> byte" to be part of the next command line argument. It is also
>> possible for the bytes that follow the string to hold system specific
>> data needed when main returns to your host environment.
>>
>> All in all it sounds like a really bad idea (tm).
....
>
> I knew I'd be bombarded with the "bad idea" comments. Thanks
> for not being too harsh. It's one of those situations when
> you have a large amount of code out there and you can't change
> some part of the code without affecting all the documentation
> that goes with it. For example, this is an old command that
> doesn't quite follow the standard convention:
>
> # old_cmd [-a time] [-b time] [-cd some_str] [-efg]
>
> A normal way would be:
>
> # new_cmd [-a time] [-b time] [--cd some_str] [--efg]
>
> Command old_cmd was written with a home brewed getopt. Without
> changing the old_cmd syntax, is there a way to change the code
> to internally mimic new_cmd in order to make use of getopt_long?
Note that you probably *will* change the syntax in other ways; if you
use getopt_long() you'll get standard Unix features like '--'
terminating the parser (ls -- -dir-), grouping of single-character
flags (ls -lf) and (unless you disable it) the ability to mix flags
and normal arguments (ls dir -l).
If you cannot get the users to adapt to subtle changes (maybe they
have scripts and stuff), keep the existing code.
/Jorgen
--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .