Advertisement

Problem With fopen() in Ubuntu

Started by March 15, 2005 11:20 AM
0 comments, last by markr 19 years, 6 months ago
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.
[SOURCE]
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);
    writeLogMessage("Sprintf'd");
    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.");
        return;
    }
    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("--PageBorder\n");
    //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.");
    //printf("\n--PageBorder--\n");
    fclose(pFinal);
  }
}

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

[/SOURCE]
[/source]
OpenGL Revolutions http://students.hightechhigh.org/~jjensen/
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.

Mark

This topic is closed to new replies.

Advertisement