Prev: What is the __dead usage macro at the start of a C program forbsd?
Next: USB stick rescue (no MBR no Partition) "Code 10"
From: Mark Hobley on 27 Feb 2010 21:08 In comp.os.linux.development.apps Mark Hobley <markhobley(a)hotpop.donottypethisbit.com> wrote: > Right. That is just as messy as __dead. I think I will just delete the tag. Right I have found another doubleunderscore thingybob. This time __progname: void usage(void) { extern char *__progname; (void)fprintf(stderr, "usage: %s [-itw] file ...\n", __progname); exit(1); } This was easier to find in google than the last one. I stumbled across: http://stackoverflow.com/questions/273691/using-progname-instead-of-argv0 This tells me that __progname is a bsdism and getopt() modifies argv[], which is not available outside of main(). I guess that I need to somehow capture argv[0] on entry to main. I guess that the following is a fixup for this: extern char *progname; int main(int argc, char *argv[]) { extern char *progname; progname=argv[0]; blah blah blah } void usage(void) { extern char *progname; (void)fprintf(stderr, "usage: %s [-itw] file ...\n", progname); exit(1); } Does that look right? Mark. -- Mark Hobley Linux User: #370818 http://markhobley.yi.org/
From: William Ahern on 28 Feb 2010 14:22
In comp.lang.c Mark Hobley <markhobley(a)hotpop.donottypethisbit.com> wrote: > In comp.os.linux.development.apps Mark Hobley <markhobley(a)hotpop.donottypethisbit.com> wrote: > > Right. That is just as messy as __dead. I think I will just delete the tag. > Right I have found another doubleunderscore thingybob. This time __progname: > void > usage(void) > { > extern char *__progname; > (void)fprintf(stderr, "usage: %s [-itw] file ...\n", __progname); > exit(1); > } > This was easier to find in google than the last one. I stumbled across: > http://stackoverflow.com/questions/273691/using-progname-instead-of-argv0 If you're only porting to Linux you can either use the getprogname() implemented in libnostd, or just read over the code in bsd/stdlib/getprogname.h. For Linux (or rather glibc and compatible libraries) the simple substitute is `extern char *program_invocation_short_name'. |