The difficulty with getting errno in this way is that by the time you
get it it may have changed from the value it had. Any calls to the
run-time system may involve a system call that could affect it.
What are you trying to get the value of errno from? If you are using
the FFI to call a function that may set errno you really need to either
return it as part of the result or save it away somewhere so you can get
it later.
David
On 11/11/2016 17:46, Kostirya wrote:
Hello.
Could you please advise a good way to obtain the errno value.
I use the following way but I don't like it:
cat errno.c
#include <errno.h>
int get_errno (void) { return errno; }
cat errno.sml
open Foreign
val errnolib = loadLibrary "errno.so"
val get_errno = buildCall0 ((getSymbol errnolib "get_errno"), (), cInt)
fun main () = print ("errno=" ^ (Int.toString (get_errno())) ^ "\n")
cc -shared -o errno.so errno.c
polyc -o errno errno.sml
env LD_LIBRARY_PATH=. ./errno
errno=0
_______________________________________________
polyml mailing list
polyml@inf.ed.ac.uk
http://lists.inf.ed.ac.uk/mailman/listinfo/polyml
_______________________________________________
polyml mailing list
polyml@inf.ed.ac.uk
http://lists.inf.ed.ac.uk/mailman/listinfo/polyml