diff options
| author | Mike Pall <mike> | 2011-05-09 11:51:19 +0200 |
|---|---|---|
| committer | Mike Pall <mike> | 2011-05-09 11:52:54 +0200 |
| commit | d9c1f771a7575510a9612e0a67be6c61d83de982 (patch) | |
| tree | 2720ba6f2288adbd9a84c178d10c228803e144bf | |
| parent | 868ecad32ba7fb3eb763642e22ebb06938fdb359 (diff) | |
| download | luajit-d9c1f771a7575510a9612e0a67be6c61d83de982.tar.gz luajit-d9c1f771a7575510a9612e0a67be6c61d83de982.tar.bz2 luajit-d9c1f771a7575510a9612e0a67be6c61d83de982.zip | |
FFI: Allow setting errno with ffi.errno(), too.
| -rw-r--r-- | doc/ext_ffi_api.html | 10 | ||||
| -rw-r--r-- | src/lib_ffi.c | 5 |
2 files changed, 10 insertions, 5 deletions
diff --git a/doc/ext_ffi_api.html b/doc/ext_ffi_api.html index 2d69cb49..e865a5f7 100644 --- a/doc/ext_ffi_api.html +++ b/doc/ext_ffi_api.html | |||
| @@ -336,14 +336,16 @@ objects. | |||
| 336 | 336 | ||
| 337 | <h2 id="util">Utility Functions</h2> | 337 | <h2 id="util">Utility Functions</h2> |
| 338 | 338 | ||
| 339 | <h3 id="ffi_errno"><tt>err = ffi.errno()</tt></h3> | 339 | <h3 id="ffi_errno"><tt>err = ffi.errno([newerr])</tt></h3> |
| 340 | <p> | 340 | <p> |
| 341 | Returns the error number set by the last C function call which | 341 | Returns the error number set by the last C function call which |
| 342 | indicated an error condition. | 342 | indicated an error condition. If the optional <tt>newerr</tt> argument |
| 343 | is present, the error number is set to the new value and the previous | ||
| 344 | value is returned. | ||
| 343 | </p> | 345 | </p> |
| 344 | <p> | 346 | <p> |
| 345 | This function offers a portable and OS-independent way to get the error | 347 | This function offers a portable and OS-independent way to get and set the |
| 346 | number. Note that only <em>some</em> C functions set the error | 348 | error number. Note that only <em>some</em> C functions set the error |
| 347 | number. And it's only significant if the function actually indicated an | 349 | number. And it's only significant if the function actually indicated an |
| 348 | error condition (e.g. with a return value of <tt>-1</tt> or | 350 | error condition (e.g. with a return value of <tt>-1</tt> or |
| 349 | <tt>NULL</tt>). Otherwise, it may or may not contain any previously set | 351 | <tt>NULL</tt>). Otherwise, it may or may not contain any previously set |
diff --git a/src/lib_ffi.c b/src/lib_ffi.c index 321de499..0f8d5013 100644 --- a/src/lib_ffi.c +++ b/src/lib_ffi.c | |||
| @@ -545,7 +545,10 @@ LJLIB_CF(ffi_offsetof) | |||
| 545 | 545 | ||
| 546 | LJLIB_CF(ffi_errno) | 546 | LJLIB_CF(ffi_errno) |
| 547 | { | 547 | { |
| 548 | setintV(L->top++, errno); | 548 | int err = errno; |
| 549 | if (L->top > L->base) | ||
| 550 | errno = ffi_checkint(L, 1); | ||
| 551 | setintV(L->top++, err); | ||
| 549 | return 1; | 552 | return 1; |
| 550 | } | 553 | } |
| 551 | 554 | ||
