errno ();
When a function fails it returns a value and optionally sets the system error number. The errno function can be used to check the current error number. To check error numbers against constant error code in your program remember to include the file with: require_lisp ("Errno.lsp");.
Calling the errno function in interactive mode does not return a valid number since you are retrieving the errno of the C function printf of the error to the screen (which will usually be 0). |
In this example, we first define a function to remove a file. Then we call that function on a non-existing file to generate an error. Finally, we check the returned error code to get the error message.
function remove_file(file) { unlink(file); errno(); } Gamma> ret_val = remove_file("/tmp/xyz"); 2 Gamma> strerror(2); "No such file or directory" Gamma>
Copyright © 1995-2010 by Cogent Real-Time Systems, Inc. All rights reserved.