NonBlockingFileIO openFile basepath


(Georgios Moschovitis) #1

I am trying to use NonBlockingFileIO to read a file.

The openFile method accepts the path of the file to open. I was expecting the path to be relative to the directory where the program is run from, but this seem to not be the case. What is the 'base-path' for the openFile method? (Absolute paths work correctly).

-g.


(Cory Benfield) #2

The NonBlockingFileIO object uses the open syscall to open the file. The open syscall evaluates paths relative to the working directory of your program. This is usually the directory the program is run from, but it is possible to change the working directory by calling chdir or fchdir

What is the 'base-path' for the openFile method? (Absolute paths work correctly).

The answer is whatever is returned by getcwd.

I take it from the question that you've seen a failed file open for a relative path. Can you give us more details on what you've seen?


(Georgios Moschovitis) #3

Hmm, I figured out what was happening.
I was running the app from within XCode, so the cwd was not what I expected. My bad.


(Helge Heß) #4

Not sure what you are trying to do, but this may be interesting to you: MicroExpress Template Lookup.


(Cory Benfield) #5

No problem, easy thing to overlook.


(Georgios Moschovitis) #6

Yes, I used:

let rootPath = "/\(#file.split(separator: "/").dropLast().joined(separator: "/"))/public"