Jump to content
  • Advertisement
Sign in to follow this  

Problem With fopen() in Ubuntu

This topic is 4994 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I wrote a function which is intended to dump html data from memory to a file on a server. I am now porting the code and it works fine on Fedora Core 2 but in Ubuntu linux it freezes inbetween writeLogMessage("Sprintf'd"); and writeLogMessage("File is attempted to have been opened."); This is disturbing because it is freezing up on an fopen() call and it does create the file (I checked). What is going on? How do I get it to return? I have never encountered anything like this. If it matters, writeLogMessage outputs the string to a file by opening it, writing it, and closing the file. I really don't know what to do and my deadline is tomorrow. Any help would be GREATLY appreciated. Thanks in advance.
void WriteOutput(int iNumber) {
  FILE *pFinal;
  writeLogMessage("Starting to write the output.");
  if(g_pData) {
    writeLogMessage("g_pData is not NULL.");
    char szName[512];
    sprintf(szName, "../Outputs/Output%d.html", iNumber);
    pFinal = fopen(szName, "w");
    writeLogMessage("File is attempted to have been opened.");
    if(pFinal==NULL) {
        writeLogMessage("File could not be opened.");
        rawErrorMessage("Could not open the output file.");
    writeLogMessage("Opened the file for writing the output.");
    //printf("Content-type: multipart/x-mixed-replace;boundary=PageBorder\n\n");    //printf("%s%c%c\n","Content-Type: multipart/mixed;boundary=PageBorder;charset=iso-8859-1", 13, 10);
    //printf("Content-Type: text/html\n\n");
    fprintf(pFinal, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<HTML>\n<HEAD>\n");
    if(g_pJavaScript) {
      fprintf(pFinal, "<SCRIPT type=\"text/javascript\">\n");
      fprintf(pFinal, "%s", g_pJavaScript);
      fprintf(pFinal, "</SCRIPT>\n");
      writeLogMessage("Wrote the javascript code to the output file.");
    fprintf(pFinal, "<TITLE>Isolation by Distance Web Service Results</TITLE>\n</HEAD>\n<BODY bgColor=\"white\" link=\"red\" vlink=\"blue\" alink=\"blue\">\n<FONT face=\"Verdana, Arial, Helvetica, sans-serif\" color=\"black\">\n");
    fprintf(pFinal, "<P><CENTER><FONT size=\"+6\">\nIBDWS Results\n</FONT></CENTER></P>\n<P><CENTER><FONT size=\"5\">2.0 Beta</FONT></CENTER></P>\n");
    fprintf(pFinal, "%s\n", g_pData);
    fprintf(pFinal, "</FONT>\n</BODY>\n</HTML>");
    writeLogMessage("Wrote all of the data to the output file.");

void writeLogMessage(const char *szMessage, ...) {         
char szBuffer[512];
        va_list ap;
        if(szMessage==NULL) {
        memset(szBuffer, '\0', 512);
        va_start(ap, szMessage);
        vsnprintf(szBuffer, 511, szMessage, ap);
        fprintf(logFile, szBuffer);
        fprintf(logFile, "\n");


Share this post

Link to post
Share on other sites
I think that your isolation of the Linux distribution as the factor which affects it is a red herring (Tux likes herrings, but not red ones).

I rather suspect that the reason behind it is either:

- Filesystem
- Locality of filesystem
- Something else

I'd ask about

- You say it's "freezing". This is very imprecise. How long is it freezing for? Is it locking up indefinitely? Can you ctrl-c it to get out?
- Are the two machines running the same hardware, filesystem, filesystem locality (if it's a networked filesystem, what networked filesystem is it, and are they on the same server?)

If you can isolate a single one of these parameters, it would be more helpful.

If it's a networked filesystem, you should probably approach your systems administrator and ask why it's behaving like that. Perhaps the file server is overloaded or the network is congested.

GNU/Linux as an operating system relies on the main components
- Linux
- Gnu LIBC

Neither of these are likely to be different between the two machines just because they're running different distros. So it's either down to hardware or configuration, I suspect.


Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!