diff --git a/Changelog.txt b/Changelog.txt index d75efbab8..0de817fb3 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -1,5 +1,6 @@ Version 6.4.1 - Added MKDIR function for BASIC +- Made _geterror() clear the error number Version 6.4.0 - Added getcrc() builtin for Spin2 diff --git a/doc/basic.md b/doc/basic.md index c53eb37c8..1509eeacb 100644 --- a/doc/basic.md +++ b/doc/basic.md @@ -2333,6 +2333,15 @@ Propeller specific builtin function. ``` Returns the error number `e` corresponding to the last system error. (This is the same as `errno` in C.) This number may be converted to a user-displayable string via `strerror$(e)`. +Note that the error number is not cleared by most library functions, and so is not always a reliable indicator of whether the last call succeeded. For that, one should use the return value of the call itself. + +`geterr` resets the error indicator to `EOK`; thus in: +``` +let r1 = geterr() +let r2 = geterr() +``` +`r2` will always be 0 (`EOK`) since there are no intervening system calls between `geterr` calls. + ### GETMS ``` diff --git a/include/libc/stdlib/errno.c b/include/libc/stdlib/errno.c index b410fe1f6..7c950afaa 100644 --- a/include/libc/stdlib/errno.c +++ b/include/libc/stdlib/errno.c @@ -3,7 +3,7 @@ static int errno; -int _geterror() { return errno; } +int _geterror() { int r = errno; errno = 0; return r; } int _seterror(int num) { errno = num; if (num) { return -1; } else return 0; } int *_geterrnoptr() { return &errno; }