Re: [PATCH] ldattach(8)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Feb 05, 2008 at 06:49:41PM -0500, Mike Frysinger wrote:
> On Tuesday 05 February 2008, Tilman Schmidt wrote:
> 
> > +static void usage(const char *prog)
> > +{
> > +    fprintf(stderr,
> > +	    "Usage: %s [ -d78neo12 ] [ -s <speed> ] <ldisc> <device>\n", prog);
> > +    exit(EXIT_FAILURE);
> > +}
> 
> i feel like "prog" should be a program-level static rather than passing around 

 glibc  program_invocation_short_name  ? :-)

> all the time.  you should also pass in the exit status instead of assuming 
> EXIT_FAILURE ... that way you can have -h (for help) exit with 0 while 
> everything else exits with 1.  and mark the function as noreturn.
> 
> > +	    fprintf(stderr, "%s: bad line discipline: %s\n", prog, optarg);
> > +	    exit(EXIT_FAILURE);
> > ...
> > +	fprintf(stderr, "%s: cannot open %s: %s\n", prog, dev, strerror(errno));
> > +	exit(EXIT_FAILURE);
> > ...
> > +	fprintf(stderr, "%s: %s is not a serial line\n", prog, dev);
> > +	exit(EXIT_FAILURE);
> > ...
> > +	fprintf(stderr, "%s: cannot set %s to exclusive mode: %s\n",
> > +		prog, dev, strerror(errno));
> > +	exit(EXIT_FAILURE);
> > ...
> > +	fprintf(stderr, "%s: cannot get terminal attributes for %s: %s\n",
> > +		prog, dev, strerror(errno));
> > +	exit(EXIT_FAILURE);
> > ...
> > <many more>
> 
> could do with writing an error function and/or macro to make things cleaner

 #include <err.h> ... err()  -- very luxury function:

    err("cannot get terminal attributes for %s", dev);

 that's all...


    Karel

-- 
 Karel Zak  <kzak@xxxxxxxxxx>
-
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux