473,396 Members | 2,121 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

What can cause a fopen call to lock up?

I'm having problems with a program I wrote- when it comes time to output
a file, the call to fopen locks up and I have to break the program
manually. I've pinpointed the actual stopping point to fopen, but due
to my lack of knowledge with gdb, etc., I don't know how to go any
further with the debugging from there.

I'm running gcc under cygwin. Sorry for the lack of information.

Here's the code in question, please no comments on style, as that is not
relevant or wanted at this time.

Other snippets-
the first (working) program was compiled alone:

gcc tracer.C

this one links with the first (what I'm doing here is seperating code
from the main functions in tracer.C so I can build some extensions off
of it easier if I need to):

gcc tracer.C raytracer_tga.C

u1, u2, and u4 are typedef'ed in tracer.h and are 1 byte, 2 byte, and 4
byte variable types, respectively.

Help me out please :)
Thanks.
#include "tracer.h"
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>

#pragma pack (1)
typedef struct {
u2 bfType;
u4 bfSize;
u2 bfReserved1;
u2 bfReserved2;
u4 bfOffBits;
} bitmapFileHeader;

typedef struct {
u4 biSize;
u4 biWidth;
u4 biHeight;
u2 biPlanes;
u2 biBitCount;
u4 biCompression;
u4 biSizeImage;
u4 biXPelsPerMeter;
u4 biYPelsPerMeter;
u4 biClrUsed;
u4 biClrImportant;
} bitmapInfoHeader;

typedef struct {
u1 idlength;
u1 colorMapType;
u1 dataTypeCode;
u2 colorMapOrigin;
u2 colorMapLength;
u1 colorMapDepth;
u2 x_origin;
u2 y_origin;
u2 width;
u2 height;
u1 bitsPerPixel;
u1 imageDescriptor;
} TgaHeader;

#pragma pack ()

(other functions...)
void writeToFile( char *filename, vec *pixels, u2 xSize, u2 ySize ) {
int i;
int y;

TgaHeader hdr;
int numPixels = xSize*ySize;

hdr.idlength = 0;
hdr.colorMapType = 0;
hdr.dataTypeCode = 2;
hdr.colorMapOrigin = 0;
hdr.colorMapLength = 0;
hdr.colorMapDepth = 0;
hdr.x_origin = 0;
hdr.y_origin = 0;
hdr.width = xSize;
hdr.height = ySize;
hdr.bitsPerPixel = 24;
hdr.imageDescriptor = 0x20;

FILE *f;

f = fopen( "out.tga", "wb" );

fwrite( &hdr, 1, sizeof( hdr ), f );

for( y = 0; y < numPixels; y++ ) {
char toWr[3];
toWr[0] = (char)(255.0*pixels[ y ].z );
toWr[1] = (char)(255.0*pixels[ y ].y ); toWr[2] = (char)(255.0*pixels[ y ].x );
fwrite( &toWr, 1, 3, f );
}
fwrite( "\0\0\0\0\0\0", 1, 6, f );
fclose( f );
}

Jul 22 '05 #1
2 2802
Mister Zimbu wrote:
I'm having problems with a program I wrote- when it comes time to output
a file, the call to fopen locks up and I have to break the program
manually. I've pinpointed the actual stopping point to fopen, but due
to my lack of knowledge with gdb, etc., I don't know how to go any
further with the debugging from there.

I'm running gcc under cygwin. Sorry for the lack of information.

[...]


Well, 'fopen' doesn't return until it either opens the stream or fails
to do so. In the former case it returns the pointer to the stream, in
the latter it returns NULL. Apparently, your implementation, when run
on your system, is doing something wrong so that 'fopen' cannot even
recognise a failure to open a file. There can be two obvious reasons
for that. (A) 'fopen' forwards the request to open the stream to some
other subsystem that itself locks up (like network file system, for
example) and you're just not patient enough to wait for it to time out,
or (b) something has screwed up the execution environment of your program
so badly that the standard library cannot work without locking up. Both
of those reasons have nothing to do with the code you posted. What is
worse, both of those situations are really difficult to diagnose and
correct.

Try asking in a gcc newsgroup or a Windows newsgroup, perhaps folks there
have experienced something like that (with cygwin) and might have more
suggestions.

Victor
Jul 22 '05 #2
Victor Bazarov wrote:

Thanks for the help; this sounds like it'll be fun :).

One oddity is this code is more or less copy-pasted from another program
written (I'm moving some functions around in that program so I can
easily extend this- ie, make builds that will render to a GL window or
another file format). The original version's backup still compiles and
runs fine.

Oh well, I'll post there in a bit. Thanks.
Mister Zimbu wrote:
I'm having problems with a program I wrote- when it comes time to
output a file, the call to fopen locks up and I have to break the
program manually. I've pinpointed the actual stopping point to fopen,
but due to my lack of knowledge with gdb, etc., I don't know how to go
any further with the debugging from there.

I'm running gcc under cygwin. Sorry for the lack of information.

[...]

Well, 'fopen' doesn't return until it either opens the stream or fails
to do so. In the former case it returns the pointer to the stream, in
the latter it returns NULL. Apparently, your implementation, when run
on your system, is doing something wrong so that 'fopen' cannot even
recognise a failure to open a file. There can be two obvious reasons
for that. (A) 'fopen' forwards the request to open the stream to some
other subsystem that itself locks up (like network file system, for
example) and you're just not patient enough to wait for it to time out,
or (b) something has screwed up the execution environment of your program
so badly that the standard library cannot work without locking up. Both
of those reasons have nothing to do with the code you posted. What is
worse, both of those situations are really difficult to diagnose and
correct.

Try asking in a gcc newsgroup or a Windows newsgroup, perhaps folks there
have experienced something like that (with cygwin) and might have more
suggestions.

Victor

Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: lkrubner | last post by:
I want to give users the power to edit files from an easy interface, so I create a form and a PHP script called "fileUpdate". It does a reasonable about of error checking and prints out some...
28
by: Sathyaish | last post by:
If fopen fails, is there a way to know why?
10
by: pjlsr | last post by:
It's close to twenty years since I used the C language and at that time I was doing only floating point computational work, nothing with strings or reading files. I tried to use fopen in the...
2
by: Kevin Frey | last post by:
Hello, I've been reading that ASP.NET serialises (ie. processes one at a time) HTTP requests if two simultaneous requests need to access the same session state. It also makes note that ASP.NET...
4
by: nde_plume | last post by:
I need a simple multi-thread/process interlock mechanism, that works on Windows and Linux. However, they have rather different mechanisms. I put together a system that seems to me to work, and be...
8
by: ecir.hana | last post by:
Dear list, maybe I'm overlooking something obvious or this is not possible at all or I don't know. Please, consider the following code: ## insert here anything you like def changer():
16
by: chutsu | last post by:
Ok Here is a problem, I got a imaginary database program that I need to code, to add a patient I have function inser_patient. but when I try to input the details it doesn't quite work the way I...
3
by: magicman | last post by:
Is difference lies in the fact that fopen part of c library and platform in-depended, whereas open is a system call? what about functionalities? thx
9
by: xiao | last post by:
It always dumped when I tried to run it... But it compiles OK. What I want to do is to do a test: Read information from a .dat file and then write it to another file. The original DAT file is...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.