Permalink
Browse files

add optional argument to errno() for setting it, and update docs. fixes

  • Loading branch information...
1 parent c9447ac commit 0304a6aa8a06c1d7988d5fa69e940f94794cef67 @JeffBezanson JeffBezanson committed Jan 24, 2014
Showing with 29 additions and 24 deletions.
  1. +2 −1 base/error.jl
  2. +25 −23 doc/stdlib/base.rst
  3. +1 −0 src/julia.h
  4. +1 −0 src/sys.c
View
@@ -32,7 +32,8 @@ catch_backtrace() = ccall(:jl_get_backtrace, Array{Ptr{Void},1}, ())
## system error handling ##
-errno() = ccall(:jl_errno, Int32, ())
+errno() = ccall(:jl_errno, Cint, ())
+errno(e::Integer) = ccall(:jl_set_errno, Void, (Cint,), e)
strerror(e::Integer) = bytestring(ccall(:strerror, Ptr{Uint8}, (Int32,), e))
strerror() = strerror(errno())
systemerror(p, b::Bool) = b ? throw(SystemError(string(p))) : nothing
View
@@ -4844,6 +4844,18 @@ C Interface
Close shared library referenced by handle.
+.. function:: find_library(names, locations)
+
+ Searches for the first library in ``names`` in the paths in the ``locations`` list, ``DL_LOAD_PATH``, or system
+ library paths (in that order) which can successfully be dlopen'd. On success, the return value will be one of
+ the names (potentially prefixed by one of the paths in locations). This string can be assigned to a ``global const``
+ and used as the library name in future ``ccall``'s. On failure, it returns the empty string.
+
+.. data:: DL_LOAD_PATH
+
+ When calling ``dlopen``, the paths in this list will be searched first, in order, before searching the
+ system locations for a valid library handle.
+
.. function:: c_malloc(size::Integer)
Call ``malloc`` from the C standard library.
@@ -4923,17 +4935,22 @@ C Interface
Re-enable Ctrl-C handler during execution of a function. Temporarily
reverses the effect of ``disable_sigint``.
-.. function:: find_library(names, locations)
+.. function:: errno([code])
- Searches for the first library in ``names`` in the paths in the ``locations`` list, ``DL_LOAD_PATH``, or system
- library paths (in that order) which can successfully be dlopen'd. On success, the return value will be one of
- the names (potentially prefixed by one of the paths in locations). This string can be assigned to a ``global const``
- and used as the library name in future ``ccall``'s. On failure, it returns the empty string.
+ Get the value of the C library's ``errno``. If an argument is specified, it is
+ used to set the value of ``errno``.
-.. data:: DL_LOAD_PATH
+ The value of ``errno`` is only valid immediately after a ``ccall`` to a C
+ library routine that sets it. Specifically, you cannot call ``errno`` at the next
+ prompt in a REPL, because lots of code is executed between prompts.
- When calling ``dlopen``, the paths in this list will be searched first, in order, before searching the
- system locations for a valid library handle.
+.. function:: systemerror(sysfunc, iftrue)
+
+ Raises a ``SystemError`` for ``errno`` with the descriptive string ``sysfunc`` if ``bool`` is true
+
+.. function:: strerror(n)
+
+ Convert a system call error code to a descriptive string
.. data:: Cchar
@@ -5030,21 +5047,6 @@ Errors
Get the backtrace of the current exception, for use within ``catch``
blocks.
-.. function:: errno()
-
- Get the value of the C library's ``errno``. As in C, ``errno()`` must be called
- directly after a function that uses ``errno`` for error reporting. Specifically
- you can not call ``errno`` on the next prompt in a REPL, because lots of code
- is executed between REPL prompts.
-
-.. function:: systemerror(sysfunc, iftrue)
-
- Raises a ``SystemError`` for ``errno`` with the descriptive string ``sysfunc`` if ``bool`` is true
-
-.. function:: strerror(n)
-
- Convert a system call error code to a descriptive string
-
.. function:: assert(cond, [text])
Raise an error if ``cond`` is false. Also available as the macro ``@assert expr``.
View
@@ -822,6 +822,7 @@ DLLEXPORT jl_value_t *jl_eqtable_get(jl_array_t *h, void *key, jl_value_t *deflt
// system information
DLLEXPORT int jl_errno(void);
+DLLEXPORT void jl_set_errno(int e);
DLLEXPORT int32_t jl_stat(const char* path, char* statbuf);
// environment entries
View
@@ -297,6 +297,7 @@ void jl_free2(void *p, void *hint)
// -- syscall utilities --
int jl_errno(void) { return errno; }
+void jl_set_errno(int e) { errno = e; }
// -- get the number of CPU cores --

0 comments on commit 0304a6a

Please sign in to comment.