[Gllug] Off Topic: C File Descriptors

Nix nix at esperi.org.uk
Sun Mar 9 22:26:01 UTC 2008


On 8 Mar 2008, Richard Jones said:

> On Fri, Mar 07, 2008 at 02:41:47AM +0100, salsaman at xs4all.nl wrote:
>> something like this (untested, YMMV) should do it:
> [appallingly bad example of C snipped]

Oh come on, he allocated a whole 512 bytes for the filename and only had
four coredump-inducing bugs, two misunderstandings of the nature of
dynamic memory allocation,, two useless uses of memset() and two blocks
of cut-and-pasted code. I've seen *much* worse.

(For a start, howsabout using 16 bytes for a filename, complete with the
omment `filenames are never longer than this'... and then they stuff an
arbitrary pathname in it...)

> Please, original poster, do NOT use this as an example.  Use fstat as
> suggested before.

It's a good example of how to coredump in very few lines.

I recommend using abort(), though.

-- 
`The rest is a tale of post and counter-post.' --- Ian Rawlings
                                                   describes USENET
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list