Re: cant figure out where the [segmentation] fault lies ??

From: Barry Margolin (barmar_at_alum.mit.edu)
Date: 09/24/05


Date: Sat, 24 Sep 2005 01:59:54 -0400

In article <1127540245.240039.71820@g14g2000cwa.googlegroups.com>,
 ebrahimbandookwala@gmail.com wrote:

> Hi Im making this fairly simple c prog which reads and writes structs
> to a file in binary . I get this stupid error when I try doing the
> following ( in deleteentry () )
>
> if(remove (filename))
> {
> if(rename (tempfile , filename))
> {
> if(!remove (tempfile))
> printf("\nFailed to remove %s" , tempfile);
> }
> else
> printf("\nFailed to rename %s" , tempfile);
> }
> else
> printf("\nFailed to remove %s" , filename );
>
> which fails at either the first level or the second. Cant figure out y
> ?? For some reason it refuses to delete the file (filename) . I also
> tried plain and simple rename(tempfile -> filename) but that too
> refuses to work ?? Maybe im overlooking something really stupid !! ..

remove() and rename() return 0 when they're successful. 0 is false when
used in an if(). So I think the sense of your tests are backward. You
want something like

if(remove(filename) == 0)

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***


Relevant Pages

  • Re: Design choice in LTC
    ... whereas you'd like to abort if it fails to ... return CRYPT_OK if the function was successful, ... it SUCCESSFULLY COMPUTED THAT THE SIGNATURE IS INVALID. ... err!= OK means it failed to even compute whether the signature ...
    (sci.crypt)
  • Re: Web Email
    ... are constraints on the size of email, ... Jay ... >> Sometimes it is successful and sometimes it fails. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Problem setting up PPPoE in Release 6.0
    ... was successful at configuring PPPoE for this combination under R5.3. ... Occasionally it fails to connect while waiting for carrier, ... delay waiting for carrier (FreeBSD checks for carrier once per second ...
    (freebsd-questions)
  • Re: CoCreateInstance fails with 0x80040150 on windows 2003
    ... Could it be that it fails to make ... succeeds when I run the exe from the command line. ... When I compare the regmon output from the successful command line case vs. ...
    (microsoft.public.win32.programmer.ole)
  • Re: PIRATE QUEEN review
    ... PIRATE QUEEN had ALW not been successful beforehand....if PIRATE QUEEN ... fails as it appears it will in NY, I think it's safe to say that the ... over THE APPLE TREE. ...
    (rec.arts.theatre.musicals)