-
Notifications
You must be signed in to change notification settings - Fork 3k
Description
Note: This is just a template, so feel free to use/remove the unnecessary things
Description
- Type: Bug
- Related issue:
#abc
- Priority: Minor
Bug
Target
K64F
Toolchain:
GCC_ARM
Toolchain version:
mbed-cli version:
1.2.0
mbed-os sha:
6e0d01c (HEAD, tag: mbed_lib_rev153, tag: mbed-os-5.6.2, origin/mbed-os-5.6) Merge pull request #5268 from ARMmbed/release-candidate
Expected behavior
When mkdir() or stat() fail for any reason, on POSIX they are document to return "-1" and errno is set appropriately.
Actual behavior
If a invalid filename is given, the errno is not set, but a -1 is returned. This will make the client code behave badly as it tries to determine error reason from errno.
Steps to reproduce
On Mbed OS 5.6.2 following code will print "mkdir err: -1, errno: 1234"
void do_error()
{
errno = 1234; // set garbage to errno, should be set to proper error code by mkdir()
int ret = mkdir("foo", 0777);
if (ret < 0) {
printf("mkdir ret: %d, errno: %d\r\n", ret, errno);
} else {
printf("mkdir ret: %d - OK\r\n", ret);
}
}
Enhancement
Reason to enhance or problem with existing solution
Suggested enhancement
Set errno also in these conditions which return -1:
https://github.com/ARMmbed/mbed-os/blob/master/platform/mbed_retarget.cpp#L682
https://github.com/ARMmbed/mbed-os/blob/master/platform/mbed_retarget.cpp#L696
Pros
Cons
Question
How to?