fopen fails with absolute path in linux host (ubuntu 20.04)

I am using ARM FVP simulator and trying to read data from a binary file in the host PC to a program running in ARM,

const char *filename = "home/dinusha/executorch/examples/arm/executor_runner/cmake-out/input.bin";

FILE* fp = fopen(filename, "rb");
if (!fp) {
ET_LOG(
Fatal,
"Could not open file %s (errno: %d) for reading, exiting!",
filename,
errno);
_exit(1);
}

Error : Could not open file home//dinusha//executorch//examples//arm//executor_runner//cmake-out//input.bin (errno: 0) for reading, exiting!

Any idea how to solve this, 

Thanks

Parents
  • Hi,

    My name is Stephen and I work at Arm.

    Are you simply missing the leading forward slash in front of "home" in the path?

    The following works for me:

    #include <stdio.h>
    #include <stdlib.h>

    int main(void)
    {
        const char *filename = "/home/stephen/test/executorch/examples/input.bin";

        FILE* fp = fopen(filename, "rb");
        if (!fp) {
            printf("fopen failed\n");
        }
        else {
            printf("fopen success\n");
        }
    }

    Note that on Windows, double backslashes must be used (to escape the path separator) in the file name.

    If that doesn't fix the issue, please let us know which version of Arm DS and which compiler (Arm Compiler 6?, GCC?) you are using.

    Hope this helps

    Stephen

Reply
  • Hi,

    My name is Stephen and I work at Arm.

    Are you simply missing the leading forward slash in front of "home" in the path?

    The following works for me:

    #include <stdio.h>
    #include <stdlib.h>

    int main(void)
    {
        const char *filename = "/home/stephen/test/executorch/examples/input.bin";

        FILE* fp = fopen(filename, "rb");
        if (!fp) {
            printf("fopen failed\n");
        }
        else {
            printf("fopen success\n");
        }
    }

    Note that on Windows, double backslashes must be used (to escape the path separator) in the file name.

    If that doesn't fix the issue, please let us know which version of Arm DS and which compiler (Arm Compiler 6?, GCC?) you are using.

    Hope this helps

    Stephen

Children