Skip to content

Commit

Permalink
Made geterr clear the error indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
totalspectrum committed Sep 8, 2023
1 parent d9190e6 commit a799e9b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions Changelog.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
9 changes: 9 additions & 0 deletions doc/basic.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

```
Expand Down
2 changes: 1 addition & 1 deletion include/libc/stdlib/errno.c
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

0 comments on commit a799e9b

Please sign in to comment.