value caml_gr_text_size(value str) { CAMLparam1(str); CAMLlocal1(res); int width; caml_gr_check_open(); if (caml_gr_font == NULL) caml_gr_get_font(DEFAULT_FONT); width = XTextWidth(caml_gr_font, String_val(str), caml_string_length(str)); res = caml_alloc_2(0, Val_int(width), Val_int(caml_gr_font->ascent + caml_gr_font->descent)); CAMLreturn(res); }
static value alloc_process_status(int pid, int status) { value st; if (WIFEXITED(status)) { st = caml_alloc_1(TAG_WEXITED, Val_int(WEXITSTATUS(status))); } else if (WIFSTOPPED(status)) { st = caml_alloc_1(TAG_WSTOPPED, Val_int(caml_rev_convert_signal_number(WSTOPSIG(status)))); } else { st = caml_alloc_1(TAG_WSIGNALED, Val_int(caml_rev_convert_signal_number(WTERMSIG(status)))); } return caml_alloc_2(0, Val_int(pid), st); }
CAMLprim value unix_pipe(value unit) { SECURITY_ATTRIBUTES attr; HANDLE readh, writeh; value readfd = Val_unit, writefd = Val_unit, res; attr.nLength = sizeof(attr); attr.lpSecurityDescriptor = NULL; attr.bInheritHandle = TRUE; if (! CreatePipe(&readh, &writeh, &attr, SIZEBUF)) { win32_maperr(GetLastError()); uerror("pipe", Nothing); } Begin_roots2(readfd, writefd) readfd = win_alloc_handle(readh); writefd = win_alloc_handle(writeh); res = caml_alloc_2(0, readfd, writefd); End_roots(); return res; }
CAMLprim value unix_getnameinfo(value vaddr, value vopts) { CAMLparam0(); CAMLlocal3(vhost, vserv, vres); union sock_addr_union addr; socklen_param_type addr_len; char host[4096]; char serv[1024]; int opts, retcode; get_sockaddr(vaddr, &addr, &addr_len); opts = convert_flag_list(vopts, getnameinfo_flag_table); enter_blocking_section(); retcode = getnameinfo((const struct sockaddr *) &addr.s_gen, addr_len, host, sizeof(host), serv, sizeof(serv), opts); leave_blocking_section(); if (retcode != 0) raise_not_found(); /* TODO: detailed error reporting? */ vhost = copy_string(host); vserv = copy_string(serv); vres = caml_alloc_2(0, vhost, vserv); CAMLreturn(vres); }