Re: C coding question
That did it! thanks so much! On 5/17/06, Lorin Lund <[EMAIL PROTECTED]> wrote: Andy Greenwood wrote: > I am helping someone work on porting some code to Freebsd, and the > code below works on Linux, but not on FreeBSD (compiles, but gives > Segmentation Fault: 11). I'm not sure where the problem is, and any > pointers would be much appreciated. > >/* Check if we must stop */ >if(tf_stat_file != NULL) >{ >tf_stat = fopen(tf_stat_file, "r"); >if (tf_stat != NULL) >{ >/* Get state */ >stat_state=fgetc(tf_stat); > >/* Torrentflux asked to shutdown the torrent */ >if (stat_state == '0') >{ >mustDie = 1; >} >} >fclose(tf_stat); >} > ___ I think I would move the fclose( tf_stat) up a line. No need to close a file that failed to open. The fclose( ) acting on a NULL pointer might be your error. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: C coding question
On 2006-05-17 14:09, Andy Greenwood <[EMAIL PROTECTED]> wrote: > I am helping someone work on porting some code to Freebsd, and the > code below works on Linux, but not on FreeBSD (compiles, but gives > Segmentation Fault: 11). I'm not sure where the problem is, and any > pointers would be much appreciated. > >/* Check if we must stop */ >if(tf_stat_file != NULL) >{ >tf_stat = fopen(tf_stat_file, "r"); >if (tf_stat != NULL) >{ >/* Get state */ >stat_state=fgetc(tf_stat); > >/* Torrentflux asked to shutdown the torrent */ >if (stat_state == '0') >{ >mustDie = 1; >} >} >fclose(tf_stat); >} Please post a complete, compilable program or at least details about where we can find the full source. This way it's impossible to find out where the bug is and why the segmentation fault happens. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: C coding question
On Wed, 17 May 2006 12:36:40 -0600 Lorin Lund <[EMAIL PROTECTED]> wrote: > Andy Greenwood wrote: > > > I am helping someone work on porting some code to Freebsd, and the > > code below works on Linux, but not on FreeBSD (compiles, but gives > > Segmentation Fault: 11). I'm not sure where the problem is, and any > > pointers would be much appreciated. > > > >/* Check if we must stop */ > >if(tf_stat_file != NULL) > >{ > >tf_stat = fopen(tf_stat_file, "r"); > >if (tf_stat != NULL) > >{ > >/* Get state */ > >stat_state=fgetc(tf_stat); > > > >/* Torrentflux asked to shutdown the torrent */ > >if (stat_state == '0') > >{ > >mustDie = 1; > >} > >} > >fclose(tf_stat); > >} > > ___ > > I think I would move the > fclose( tf_stat) > up a line. No need to close a file that failed to open. The fclose( ) > acting on > a NULL pointer might be your error. >From man fclose: The fclose() function does not handle NULL arguments; they will result in a segmentation violation. This is intentional - it makes it easier to make sure programs written under FreeBSD are bug free. This behaviour is an implementation detail, and programs should not rely upon it. Good catch. -- Bill Moran Collaborative Fusion Inc. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: C coding question
On 5/17/06, Micah <[EMAIL PROTECTED]> wrote: Andy Greenwood wrote: > I am helping someone work on porting some code to Freebsd, and the > code below works on Linux, but not on FreeBSD (compiles, but gives > Segmentation Fault: 11). I'm not sure where the problem is, and any > pointers would be much appreciated. That's funny, it doesn't even compile on my freebsd: trisha% cat test.c /* Check if we must stop */ if(tf_stat_file != NULL) { tf_stat = fopen(tf_stat_file, "r"); if (tf_stat != NULL) { /* Get state */ stat_state=fgetc(tf_stat); /* Torrentflux asked to shutdown the torrent */ if (stat_state == '0') { mustDie = 1; } } fclose(tf_stat); } trisha% cc test.c test.c:2: error: syntax error before "if" AFAIK, the code should be put inside a function at least to compile ;-) IOW, if you expect usable help please supply some context. I agree.. Later, Micah ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]" -- Pietro Cerutti ICQ: 117293691 PGP: 0x9571F78E - ASCII Ribbon Campaign - against HTML e-mail and proprietary attachments www.asciiribbon.org ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: C coding question
Andy Greenwood wrote: I am helping someone work on porting some code to Freebsd, and the code below works on Linux, but not on FreeBSD (compiles, but gives Segmentation Fault: 11). I'm not sure where the problem is, and any pointers would be much appreciated. /* Check if we must stop */ if(tf_stat_file != NULL) { tf_stat = fopen(tf_stat_file, "r"); if (tf_stat != NULL) { /* Get state */ stat_state=fgetc(tf_stat); /* Torrentflux asked to shutdown the torrent */ if (stat_state == '0') { mustDie = 1; } } fclose(tf_stat); } ___ I think I would move the fclose( tf_stat) up a line. No need to close a file that failed to open. The fclose( ) acting on a NULL pointer might be your error. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: C coding question
Andy Greenwood wrote: I am helping someone work on porting some code to Freebsd, and the code below works on Linux, but not on FreeBSD (compiles, but gives Segmentation Fault: 11). I'm not sure where the problem is, and any pointers would be much appreciated. That's funny, it doesn't even compile on my freebsd: trisha% cat test.c /* Check if we must stop */ if(tf_stat_file != NULL) { tf_stat = fopen(tf_stat_file, "r"); if (tf_stat != NULL) { /* Get state */ stat_state=fgetc(tf_stat); /* Torrentflux asked to shutdown the torrent */ if (stat_state == '0') { mustDie = 1; } } fclose(tf_stat); } trisha% cc test.c test.c:2: error: syntax error before "if" IOW, if you expect usable help please supply some context. Later, Micah ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"