static value stat_aux(/*int use_64,*/ struct stat *buf) { CAMLparam0(); CAMLlocal5(atime, mtime, ctime, offset, v); atime = caml_copy_double((double) buf->st_atime); mtime = caml_copy_double((double) buf->st_mtime); ctime = caml_copy_double((double) buf->st_ctime); offset = /*use_64 ? Val_file_offset(buf->st_size) :*/ Val_int (buf->st_size); v = caml_alloc_small(12, 0); Field (v, 0) = Val_int (buf->st_dev); Field (v, 1) = Val_int (buf->st_ino); Field (v, 2) = cst_to_constr(buf->st_mode & S_IFMT, file_kind_table, sizeof(file_kind_table) / sizeof(int), 0); Field (v, 3) = Val_int (buf->st_mode & 07777); Field (v, 4) = Val_int (buf->st_nlink); Field (v, 5) = Val_int (buf->st_uid); Field (v, 6) = Val_int (buf->st_gid); Field (v, 7) = Val_int (buf->st_rdev); Field (v, 8) = offset; Field (v, 9) = atime; Field (v, 10) = mtime; Field (v, 11) = ctime; CAMLreturn(v); }
void ns_unix_error(int errcode, char *cmdname, value cmdarg) { CAMLparam0(); CAMLlocal4(res,name,err,arg); name = err = arg = Val_unit; Begin_roots3 (name, err, arg); arg = cmdarg == Nothing ? copy_string("") : cmdarg; name = copy_string(cmdname); err = cst_to_constr(errcode, ns_error_table, sizeof(ns_error_table)/sizeof(int)); if (unix_error_exn == NULL) { unix_error_exn = caml_named_value("Ocamllib.Unix_error"); if (unix_error_exn == NULL) invalid_argument("Exception Ocamllib.Unix_error not initialized, please link Ocamllib.cma"); } res = alloc_small(4, 0); Field(res, 0) = *unix_error_exn; Field(res, 1) = err; Field(res, 2) = name; Field(res, 3) = arg; End_roots(); mlraise(res); CAMLreturn0; }
static value stat_aux(int use_64, struct stat *buf) { CAMLparam0(); CAMLlocal5(atime, mtime, ctime, offset, v); #include "nanosecond_stat.h" atime = caml_copy_double((double) buf->st_atime + (NSEC(buf, a) / 1000000000.0)); mtime = caml_copy_double((double) buf->st_mtime + (NSEC(buf, m) / 1000000000.0)); ctime = caml_copy_double((double) buf->st_ctime + (NSEC(buf, c) / 1000000000.0)); #undef NSEC offset = use_64 ? Val_file_offset(buf->st_size) : Val_int (buf->st_size); v = alloc_small(12, 0); Init_field(v, 0, Val_int (buf->st_dev)); Init_field(v, 1, Val_int (buf->st_ino)); Init_field(v, 2, cst_to_constr(buf->st_mode & S_IFMT, file_kind_table, sizeof(file_kind_table) / sizeof(int), 0)); Init_field(v, 3, Val_int (buf->st_mode & 07777)); Init_field(v, 4, Val_int (buf->st_nlink)); Init_field(v, 5, Val_int (buf->st_uid)); Init_field(v, 6, Val_int (buf->st_gid)); Init_field(v, 7, Val_int (buf->st_rdev)); Init_field(v, 8, offset); Init_field(v, 9, atime); Init_field(v, 10, mtime); Init_field(v, 11, ctime); CAMLreturn(v); }
static value convert_addrinfo(struct addrinfo * a) { CAMLparam0(); CAMLlocal3(vres,vaddr,vcanonname); union sock_addr_union sa; socklen_param_type len; len = a->ai_addrlen; if (len > sizeof(sa)) len = sizeof(sa); memcpy(&sa.s_gen, a->ai_addr, len); vaddr = alloc_sockaddr(&sa, len, -1); vcanonname = copy_string(a->ai_canonname == NULL ? "" : a->ai_canonname); vres = alloc_small(5, 0); Field(vres, 0) = cst_to_constr(a->ai_family, socket_domain_table, 3, 0); Field(vres, 1) = cst_to_constr(a->ai_socktype, socket_type_table, 4, 0); Field(vres, 2) = Val_int(a->ai_protocol); Field(vres, 3) = vaddr; Field(vres, 4) = vcanonname; CAMLreturn(vres); }
value unix_error_of_code (int errcode) { int errconstr; value err; errconstr = cst_to_constr(errcode, error_table, sizeof(error_table)/sizeof(int), -1); if (errconstr == Val_int(-1)) { err = alloc_small(1, 0); Field(err, 0) = Val_int(errcode); } else { err = errconstr; } return err; }
static value stat_aux(int use_64, struct _stati64 *buf) { CAMLparam0 (); CAMLlocal1 (v); v = caml_alloc (12, 0); Store_field (v, 0, Val_int (buf->st_dev)); Store_field (v, 1, Val_int (buf->st_ino)); Store_field (v, 2, cst_to_constr (buf->st_mode & S_IFMT, file_kind_table, sizeof(file_kind_table) / sizeof(int), 0)); Store_field (v, 3, Val_int(buf->st_mode & 07777)); Store_field (v, 4, Val_int (buf->st_nlink)); Store_field (v, 5, Val_int (buf->st_uid)); Store_field (v, 6, Val_int (buf->st_gid)); Store_field (v, 7, Val_int (buf->st_rdev)); Store_field (v, 8, use_64 ? copy_int64(buf->st_size) : Val_int (buf->st_size)); Store_field (v, 9, copy_double((double) buf->st_atime)); Store_field (v, 10, copy_double((double) buf->st_mtime)); Store_field (v, 11, copy_double((double) buf->st_ctime)); CAMLreturn (v); }
CAMLprim value netcgi2_apache_request_finfo (value rv) { CAMLparam1 (rv); request_rec *r = Request_rec_val (rv); CAMLlocal5 (v, sb, atime, mtime, ctime); #if APACHE2 if (r->finfo.filetype != APR_NOFILE) /* Some statbuf */ { atime = (r->finfo.valid & APR_FINFO_ATIME) ? copy_double ((double) apr_time_sec (r->finfo.atime)) : copy_double (0.); mtime = (r->finfo.valid & APR_FINFO_MTIME) ? copy_double ((double) apr_time_sec (r->finfo.mtime)) : copy_double (0.); ctime = (r->finfo.valid & APR_FINFO_CTIME) ? copy_double ((double) apr_time_sec (r->finfo.ctime)) : copy_double (0.); sb = alloc_small (12, 0); Field (sb, 0) = Val_int (r->finfo.device); Field (sb, 1) = Val_int (r->finfo.inode); Field (sb, 2) = cst_to_constr (r->finfo.filetype, file_kind_table, sizeof (file_kind_table) / sizeof (int), 0); Field (sb, 3) = Val_int (r->finfo.protection); Field (sb, 4) = Val_int (r->finfo.nlink); Field (sb, 5) = Val_int (r->finfo.user); Field (sb, 6) = Val_int (r->finfo.group); Field (sb, 7) = Val_int (0); /* FIXME rdev? */ Field (sb, 8) = Val_int (r->finfo.size); /* FIXME 64 bit file offsets */ Field (sb, 9) = atime; Field (sb, 10) = mtime; Field (sb, 11) = ctime; v = alloc (1, 0); /* The "Some" block. */ Field (v, 0) = sb; } else v = Val_int (0); /* None. */ #else /* not APACHE2 */ if (r->finfo.st_mode) /* Some statbuf */ { /* This code copied and modified from otherlibs/unix/stat.c. */ atime = copy_double ((double) r->finfo.st_atime); mtime = copy_double ((double) r->finfo.st_mtime); ctime = copy_double ((double) r->finfo.st_ctime); sb = alloc_small (12, 0); Field (sb, 0) = Val_int (r->finfo.st_dev); Field (sb, 1) = Val_int (r->finfo.st_ino); Field (sb, 2) = cst_to_constr (r->finfo.st_mode & S_IFMT, file_kind_table, sizeof (file_kind_table) / sizeof (int), 0); Field (sb, 3) = Val_int (r->finfo.st_mode & 07777); Field (sb, 4) = Val_int (r->finfo.st_nlink); Field (sb, 5) = Val_int (r->finfo.st_uid); Field (sb, 6) = Val_int (r->finfo.st_gid); Field (sb, 7) = Val_int (r->finfo.st_rdev); Field (sb, 8) = Val_int (r->finfo.st_size); /* FIXME: 64 bit file offsets */ Field (sb, 9) = atime; Field (sb, 10) = mtime; Field (sb, 11) = ctime; v = alloc (1, 0); /* The "Some" block. */ Field (v, 0) = sb; } else v = Val_int (0); /* None. */ #endif /* not APACHE2 */ CAMLreturn (v); }