value guestfs_int_mllib_parse_uri (value argv /* arg value, not an array! */) { CAMLparam1 (argv); CAMLlocal4 (rv, sv, ssv, ov); struct uri uri; int r; r = parse_uri (String_val (argv), &uri); if (r == -1) caml_invalid_argument ("URI.parse_uri"); /* Convert the struct into an OCaml tuple. */ rv = caml_alloc_tuple (5); /* path : string */ sv = caml_copy_string (uri.path); free (uri.path); Store_field (rv, 0, sv); /* protocol : string */ sv = caml_copy_string (uri.protocol); free (uri.protocol); Store_field (rv, 1, sv); /* server : string array option */ if (uri.server) { ssv = caml_copy_string_array ((const char **) uri.server); guestfs_int_free_string_list (uri.server); ov = caml_alloc (1, 0); Store_field (ov, 0, ssv); } else ov = Val_int (0); Store_field (rv, 2, ov); /* username : string option */ if (uri.username) { sv = caml_copy_string (uri.username); free (uri.username); ov = caml_alloc (1, 0); Store_field (ov, 0, sv); } else ov = Val_int (0); Store_field (rv, 3, ov); /* password : string option */ if (uri.password) { sv = caml_copy_string (uri.password); free (uri.password); ov = caml_alloc (1, 0); Store_field (ov, 0, sv); } else ov = Val_int (0); Store_field (rv, 4, ov); CAMLreturn (rv); }
CAMLprim value caml_sys_get_argv(value unit) { CAMLparam0 (); /* unit is unused */ CAMLlocal3 (exe_name, argv, res); exe_name = caml_copy_string(caml_exe_name); argv = caml_copy_string_array((char const **) caml_main_argv); res = caml_alloc_small(2, 0); Field(res, 0) = exe_name; Field(res, 1) = argv; CAMLreturn(res); }
static value alloc_group_entry(struct group *entry) { value res; value name = Val_unit, pass = Val_unit, mem = Val_unit; Begin_roots3 (name, pass, mem); name = caml_copy_string(entry->gr_name); pass = caml_copy_string(entry->gr_passwd); mem = caml_copy_string_array((const char**)entry->gr_mem); res = caml_alloc_4(0, name, pass, Val_int(entry->gr_gid), mem); End_roots(); return res; }
CAMLprim value caml_sys_read_directory(value path) { CAMLparam1(path); CAMLlocal1(result); struct ext_table tbl; caml_ext_table_init(&tbl, 50); if (caml_read_directory(String_val(path), &tbl) == -1){ caml_ext_table_free(&tbl, 1); caml_sys_error(path); } caml_ext_table_add(&tbl, NULL); result = caml_copy_string_array((char const **) tbl.contents); caml_ext_table_free(&tbl, 1); CAMLreturn(result); }
CAMLprim value caml_sys_read_directory(value path) { CAMLparam1(path); CAMLlocal1(result); struct ext_table tbl; char * p; int ret; caml_ext_table_init(&tbl, 50); p = caml_strdup(String_val(path)); caml_enter_blocking_section(); ret = caml_read_directory(p, &tbl); caml_leave_blocking_section(); caml_stat_free(p); if (ret == -1){ caml_ext_table_free(&tbl, 1); caml_sys_error(path); } caml_ext_table_add(&tbl, NULL); result = caml_copy_string_array((char const **) tbl.contents); caml_ext_table_free(&tbl, 1); CAMLreturn(result); }