Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extern int code_of_unix_error (value error); #4812

Closed
vicuna opened this issue Jun 3, 2009 · 1 comment
Closed

Add extern int code_of_unix_error (value error); #4812

vicuna opened this issue Jun 3, 2009 · 1 comment

Comments

@vicuna
Copy link

@vicuna vicuna commented Jun 3, 2009

Original bug ID: 4812
Reporter: goswin
Status: closed (set by @damiendoligez on 2013-08-02T14:21:48Z)
Resolution: fixed
Priority: high
Severity: minor
Target version: 4.01.0+dev
Fixed in version: 4.01.0+dev
Category: ~DO NOT USE (was: OCaml general)
Monitored by: tgazagna @ygrek @glondu

Bug description

The unixsupport.h header provides functions to convert unix errno into ocamls Unix.error, which is sufficient for most applications. The attached patch adds a function for the reverse convertion.

Additional information

Rational:
For libfuse bindings I need to convert Unix.error to errno numbers. The C stubs call an ocaml closure and expect usualy a string as return value or an Unix.Unix_error exception in case of an error. The stubs need to catch the exception, convert them back to unix errno numbers and return -err to libfuse. The code looks something like this:

static int readlink_stub(const char *name, char *buf, size_t size) {
int res = 0;
leave_blocking_section();
CAMLparam0();
CAMLlocal3(ml_name, ml_res, ml_exn);

ml_name = caml_copy_string(name);
value ml_res = caml_callback2(readlink_callback, ml_name, Val_int(size));
if (Is_exception_result(ml_res)) {
ml_exn = Extract_exception(ml_res);
res = -code_of_unix_error(Field(ml_exn, 1));
} else {
strncpy(buf, String_val(ml_res), size);
}
enter_blocking_section();
return res;
}

File attachments

@vicuna
Copy link
Author

@vicuna vicuna commented Aug 2, 2013

Comment author: @damiendoligez

Patch applied (branch 4.01, rev 13968)

@vicuna vicuna closed this Aug 2, 2013
@vicuna vicuna added this to the 4.01.0 milestone Mar 14, 2019
@vicuna vicuna added the bug label Mar 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant