0

I wrote a functino which runs on linux generates some files on linux while processing data. I called that function in rtems (a real-time OS) and it's compiled ok and largely seems to be running fine. But I found it cannot create result file (which is an option) in the speicified directory. (I'm using SD card for file system). I have a test program I wrote a year ago where I test file read, write and copy on the SD card and there everything is ok. But in this new application which I made by modifying the SD card test program and adding more stuff (related to deep-learning), the program can't make a file. In the code, it checks if a directory called 'result' exists and if not, makes the directory and generates files looping through index. I hope someone could find what the problem is. The headers are ok both for linux and rtems. (rtems has the same headers) The file system is monted ok and mkdir returns 0. I tried adding some headers from rtems (from the well-running test program) but it didn't work. What could be the problem? Any help or suggestion appreciated.

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <sys/stat.h>

lrn_layer(,...)
{
...
if (save_output) {
        if (stat("result", &st) == -1) {
            printf("making directory 'result'..\n");
            #ifdef _RTEMS_
            rtems_status_code status = mkdir("result", 0777);
            printf("mkdir status = %d\n", status);
            #else
            mkdir("result", 0777);
            #endif
        }
        else {
            printf("directory 'result' exists..\n");
        }

        sprintf(str, "./result/L%02d_ReLU_T000_FN%03d.txt", layer, ofm_idx);
        file = fopen(str, "w");
        printf("writing relu result to file %s ..\n", str);
        for (rix = 0; rix < H; rix++) {
            fprintf(file, "### kr = %d ##\n", rix);
            for (cix = 0; cix < W; cix++) {
                fprintf(file, "%f ",*(top+ofm_idx*H*W+rix*W+cix));
                if (cix %8 == 7) fprintf(file, "\n");
            }
        }
        fclose(file);
}
...
}

Below is part of processing result :

---- Layer 1 : ReLU ----
reading inputs from files..
doing ReLu..
making OFM 0 / 96
making directory 'result'..
mkdir status = 0
writing relu result to file ./result/L01_ReLU_T000_FN000.txt ..
making OFM 1 / 96
stat = 0
directory 'result' exists..
writing relu result to file ./result/L01_ReLU_T000_FN001.txt ..
making OFM 2 / 96
stat = 0
directory 'result' exists..
writing relu result to file ./result/L01_ReLU_T000_FN002.txt ..
Chan Kim
  • 5,177
  • 12
  • 57
  • 112
  • You're not checking the return values from `fopen()` or `fprintf()`. How do you know that they succeeded? – Andrew Henle Nov 15 '16 at 10:38
  • Oh, I later found the absolute path was set wrong. I remember fopen and fprintf returned ok (maybe I'm confused from multiple debug cases..) I guess the stat function and fopen return value doesn't return correct value for error checking. And one more, I had to change fprintf(%f ) to fputc somehow.. – Chan Kim Nov 17 '16 at 09:08

0 Answers0