[Answered] Virtual File System: Returning an error code ...

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

[Answered] Virtual File System: Returning an error code ...

Postby kolban » Sat Nov 05, 2016 4:56 pm

When we implement a VFS and wish to return an error code, what is the correct way to perform that task?

For example, I am imagining an underlying call to open() to open a file. If the file does not actually exist, what is the correct procedure to return such an indication? In Unix, I believe open() would return "-1" and the global errno would indicate the last error. In the ESP-IDF environment, should we return -1 from our VFS function and set errno explicitly before return?
Last edited by kolban on Sun Nov 06, 2016 4:37 pm, edited 1 time in total.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

ESP_igrr
Posts: 2067
Joined: Tue Dec 01, 2015 8:37 am

Re: Virtual File System: Returning an error code ...

Postby ESP_igrr » Sun Nov 06, 2016 5:37 am

Yes, setting errno and returning -1 is the correct way. Newlib will check the return value and propagate the error to the calling function (e.g. return NULL from fopen).
I suppose that even though this is the way 'open' syscall operates on other systems, I need to include these semantics into the documentation.

tangqingcai
Posts: 12
Joined: Thu Mar 23, 2017 3:05 am

Re: [Answered] Virtual File System: Returning an error code ...

Postby tangqingcai » Fri Mar 23, 2018 6:28 am

hi,could you tell me something about file operation in esp32-idf;
i mean that there are some examples in esp32-idf;
but i can not understand how fopen,fprintf,fget,fclose worked;
i do not find the source code;
so i want to know where is the introduction about esp32-idf's file operation api;


tangqingcai
Posts: 12
Joined: Thu Mar 23, 2017 3:05 am

Re: [Answered] Virtual File System: Returning an error code ...

Postby tangqingcai » Fri Mar 23, 2018 9:30 am

ahaha;
thank you very much ,WiFive;
it is all of the standard C library file operation functions;

Who is online

Users browsing this forum: ESP_Roland and 122 guests