|FROM ||Ruben I Safir
|SUBJECT ||Re: [hangout] Debugging cdparanoia in C
It's funny, but even as rusty as I am in C and clueless in Unix
functions in C, I'm still finding amature like mistakes in the
code for cdparanioa
Look at this snippet of code for example. This works, but it
should be programed more correctly (unless I'm missing something).
/* is it a name or a pattern? */
/* try first eight of each device */
/* number, then letter */
Breaking this function down -
cdrom is an array of char pointers to possible cdrom devices
if the array string has a '?' in it, then search for various devices by numbers and letter (such as /dev/hda1, /dev/hda2, ect)
pos is returned the position for the '?' in the string
from 0-4 then COPY the contents of the string in cdrom_device[i] into *buffer <<<=========== FOR EVERY TIME THROUGH THE LOOP.
They SHOULD copy the string into the buffer FIRST. I'd imagine that the optimizer fixes this, but this is the kind of mistakes in
coding which used to drive me NUTS. First, it adds a line into the loop. Second, your acking the system to do something over and
over again which needs to be done only ONCE. In a different situation, this kind of carelessness creates difficult to track bugs.
On 2004.04.20 15:05 Billy wrote:
> On Tue, Apr 20, 2004 at 02:16:34PM -0400, Ruben I Safir wrote:
> > Somebody might find it interesting.
> > > Is there a reason I should be?
> > >
> > What is happening with this line:
> > if(lstat("/dev/cdrom",&s))
> > lstat returns a 0 or a -1 and both are false
> any nonzero number is true in C.
Brooklyn Linux Solutions
So many immigrant groups have swept through our town
that Brooklyn, like Atlantis, reaches mythological
proportions in the mind of the world - RI Safir 1998
DRM is THEFT - We are the STAKEHOLDERS - RI Safir 2002
http://www.mrbrklyn.com - Consulting
http://www.inns.net <-- Happy Clients
http://www.nylxs.com - Leadership Development in Free Software
http://www2.mrbrklyn.com/resources - Unpublished Archive or stories and articles from around the net
http://www2.mrbrklyn.com/downtown.html - See the New Downtown Brooklyn....
NYLXS: New Yorker Free Software Users Scene
Fair Use -
because it's either fair use or useless....
NYLXS is a trademark of NYLXS, Inc