Subject: Re: My new fdisk(8) program.
To: None <tech-toolchain@NetBSD.org>
From: George Peter Staplin <GeorgePS@XMission.com>
Date: 02/02/2004 15:57:13
On Sun, 1 Feb 2004, slick wrote:
> Date: Sun, 01 Feb 2004 22:12:13 -0500
> From: slick <email@example.com>
> To: tech-toolchain@NetBSD.org
> Subject: My new fdisk(8) program.
> I decided to write a new fdisk(8) program for unix. The main goal was to be
> able to do all the MBR manipulation from the command line, to be portable
> across all unix platform using libc, to work alone, to be as small and
> simple as possible and to be easy to maintain and extend.
> I did it.
> - do anything the exiting fdisk(8) do and even more(also more to come).
> - compiles, run and work on any sane unix platform with standard libc.
> - has no need for anything else than "/bin/sh" and "/usr/lib/libc*".
> - is 10 times smaller.
> - in pure C.
> - has no struct.
> I tested it, but you know I might have forget some details or even do
> things better.
> Please review the code, the structure, the functionality and the error
> I accept any (good and/or bad) feedback if its constructive.
> Thanks for taking the time to do so and if you don't thanks anyway...
1. make the return of main be int, because IIRC newer C standards have
made it so that there is no default return of int for functions anymore.
2. don't return exit (-1). use EXIT_FAILURE defined in stdlib.h
3. factor your code more with macros and functions, so that you minimize
repeats and make the code more readable.
4. the code in start() which invokes main will call exit for you
automatically using whatever value you return from main. In fact it's
usually defined like: exit(main(argc,argv));
5. follow the coding standards for NetBSD as demonstrated in
6. test your code with -Wall and -W with gcc.
Note: I happen to disagree with the style guide rev 18.104.22.168, because it
says to return 0 on success, and 1 on failure. This is bad style IMO,
because we have EXIT_SUCCESS and EXIT_FAILURE for such things, which are
more readable and portable. An OS that uses C is not required to have 0
be for success -- even though most do so.
Bringing you quality nerdy products since 1981.