FILEHANDLE local_file_open(const char* name, int flags) { int openmode = posix_to_semihost_open_flags(flags); if (openmode == OPEN_INVALID) { return (FILEHANDLE)NULL; } FILEHANDLE fh = semihost_open(name, openmode); if (fh == -1) { return (FILEHANDLE)NULL; } return fh; }
FileHandle *LocalFileSystem::open(const char* name, int flags) { /* reject filenames with / in them */ for (const char *tmp = name; *tmp; tmp++) { if (*tmp == '/') { return NULL; } } int openmode = posix_to_semihost_open_flags(flags); if (openmode == OPEN_INVALID) { return NULL; } FILEHANDLE fh = semihost_open(name, openmode); if (fh == -1) { return NULL; } return new LocalFileHandle(fh); }
int LocalFileSystem::open(FileHandle **file, const char* name, int flags) { // No global state modified so function is thread safe /* reject filenames with / in them */ for (const char *tmp = name; *tmp; tmp++) { if (*tmp == '/') { return -EINVAL; } } int openmode = posix_to_semihost_open_flags(flags); if (openmode == OPEN_INVALID) { return -EINVAL; } FILEHANDLE fh = semihost_open(name, openmode); if (fh == -1) { return -EIO; } *file = new LocalFileHandle(fh); return 0; }