123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301(* This file is part of Luv, released under the MIT license. See LICENSE.md for
details, or visit https://github.com/aantron/luv/blob/master/LICENSE.md. *)typet=[|`E2BIG|`EACCES|`EADDRINUSE|`EADDRNOTAVAIL|`EAFNOSUPPORT|`EAGAIN|`EAI_ADDRFAMILY|`EAI_AGAIN|`EAI_BADFLAGS|`EAI_BADHINTS|`EAI_CANCELED|`EAI_FAIL|`EAI_FAMILY|`EAI_MEMORY|`EAI_NODATA|`EAI_NONAME|`EAI_OVERFLOW|`EAI_PROTOCOL|`EAI_SERVICE|`EAI_SOCKTYPE|`EALREADY|`EBADF|`EBUSY|`ECANCELED|`ECONNABORTED|`ECONNREFUSED|`ECONNRESET|`EDESTADDRREQ|`EEXIST|`EFAULT|`EFBIG|`EFTYPE|`EHOSTUNREACH|`EILSEQ|`EINTR|`EINVAL|`EIO|`EISCONN|`EISDIR|`ELOOP|`EMFILE|`EMSGSIZE|`ENAMETOOLONG|`ENETDOWN|`ENETUNREACH|`ENFILE|`ENOBUFS|`ENODEV|`ENOENT|`ENOMEM|`ENONET|`ENOPROTOOPT|`ENOSPC|`ENOSYS|`ENOTCONN|`ENOTDIR|`ENOTEMPTY|`ENOTSOCK|`ENOTSUP|`ENOTTY|`EPERM|`EPIPE|`EPROTO|`EPROTONOSUPPORT|`EPROTOTYPE|`ERANGE|`EROFS|`ESHUTDOWN|`ESPIPE|`ESRCH|`ETIMEDOUT|`ETXTBSY|`EXDEV|`UNKNOWN|`EOF|`ENXIO|`EMLINK]letto_c=letopenC.Types.Errorinfunction|`E2BIG->e2big|`EACCES->eacces|`EADDRINUSE->eaddrinuse|`EADDRNOTAVAIL->eaddrnotavail|`EAFNOSUPPORT->eafnosupport|`EAGAIN->eagain|`EAI_ADDRFAMILY->eai_addrfamily|`EAI_AGAIN->eai_again|`EAI_BADFLAGS->eai_badflags|`EAI_BADHINTS->eai_badhints|`EAI_CANCELED->eai_canceled|`EAI_FAIL->eai_fail|`EAI_FAMILY->eai_family|`EAI_MEMORY->eai_memory|`EAI_NODATA->eai_nodata|`EAI_NONAME->eai_noname|`EAI_OVERFLOW->eai_overflow|`EAI_PROTOCOL->eai_protocol|`EAI_SERVICE->eai_service|`EAI_SOCKTYPE->eai_socktype|`EALREADY->ealready|`EBADF->ebadf|`EBUSY->ebusy|`ECANCELED->ecanceled|`ECONNABORTED->econnaborted|`ECONNREFUSED->econnrefused|`ECONNRESET->econnreset|`EDESTADDRREQ->edestaddrreq|`EEXIST->eexist|`EFAULT->efault|`EFBIG->efbig|`EFTYPE->eftype|`EHOSTUNREACH->ehostunreach|`EILSEQ->eilseq|`EINTR->eintr|`EINVAL->einval|`EIO->eio|`EISCONN->eisconn|`EISDIR->eisdir|`ELOOP->eloop|`EMFILE->emfile|`EMSGSIZE->emsgsize|`ENAMETOOLONG->enametoolong|`ENETDOWN->enetdown|`ENETUNREACH->enetunreach|`ENFILE->enfile|`ENOBUFS->enobufs|`ENODEV->enodev|`ENOENT->enoent|`ENOMEM->enomem|`ENONET->enonet|`ENOPROTOOPT->enoprotoopt|`ENOSPC->enospc|`ENOSYS->enosys|`ENOTCONN->enotconn|`ENOTDIR->enotdir|`ENOTEMPTY->enotempty|`ENOTSOCK->enotsock|`ENOTSUP->enotsup|`ENOTTY->enotty|`EPERM->eperm|`EPIPE->epipe|`EPROTO->eproto|`EPROTONOSUPPORT->eprotonosupport|`EPROTOTYPE->eprototype|`ERANGE->erange|`EROFS->erofs|`ESHUTDOWN->eshutdown|`ESPIPE->espipe|`ESRCH->esrch|`ETIMEDOUT->etimedout|`ETXTBSY->etxtbsy|`EXDEV->exdev|`UNKNOWN->unknown|`EOF->eof|`ENXIO->enxio|`EMLINK->emlinkletfrom_c=letopenC.Types.Errorinfunction|ewhene=e2big->`E2BIG|ewhene=eacces->`EACCES|ewhene=eaddrinuse->`EADDRINUSE|ewhene=eaddrnotavail->`EADDRNOTAVAIL|ewhene=eafnosupport->`EAFNOSUPPORT|ewhene=eagain->`EAGAIN|ewhene=eai_addrfamily->`EAI_ADDRFAMILY|ewhene=eai_again->`EAI_AGAIN|ewhene=eai_badflags->`EAI_BADFLAGS|ewhene=eai_badhints->`EAI_BADHINTS|ewhene=eai_canceled->`EAI_CANCELED|ewhene=eai_fail->`EAI_FAIL|ewhene=eai_family->`EAI_FAMILY|ewhene=eai_memory->`EAI_MEMORY|ewhene=eai_nodata->`EAI_NODATA|ewhene=eai_noname->`EAI_NONAME|ewhene=eai_overflow->`EAI_OVERFLOW|ewhene=eai_protocol->`EAI_PROTOCOL|ewhene=eai_service->`EAI_SERVICE|ewhene=eai_socktype->`EAI_SOCKTYPE|ewhene=ealready->`EALREADY|ewhene=ebadf->`EBADF|ewhene=ebusy->`EBUSY|ewhene=ecanceled->`ECANCELED|ewhene=econnaborted->`ECONNABORTED|ewhene=econnrefused->`ECONNREFUSED|ewhene=econnreset->`ECONNRESET|ewhene=edestaddrreq->`EDESTADDRREQ|ewhene=eexist->`EEXIST|ewhene=efault->`EFAULT|ewhene=efbig->`EFBIG|ewhene=eftype->`EFTYPE|ewhene=ehostunreach->`EHOSTUNREACH|ewhene=eilseq->`EILSEQ|ewhene=eintr->`EINTR|ewhene=einval->`EINVAL|ewhene=eio->`EIO|ewhene=eisconn->`EISCONN|ewhene=eisdir->`EISDIR|ewhene=eloop->`ELOOP|ewhene=emfile->`EMFILE|ewhene=emsgsize->`EMSGSIZE|ewhene=enametoolong->`ENAMETOOLONG|ewhene=enetdown->`ENETDOWN|ewhene=enetunreach->`ENETUNREACH|ewhene=enfile->`ENFILE|ewhene=enobufs->`ENOBUFS|ewhene=enodev->`ENODEV|ewhene=enoent->`ENOENT|ewhene=enomem->`ENOMEM|ewhene=enonet->`ENONET|ewhene=enoprotoopt->`ENOPROTOOPT|ewhene=enospc->`ENOSPC|ewhene=enosys->`ENOSYS|ewhene=enotconn->`ENOTCONN|ewhene=enotdir->`ENOTDIR|ewhene=enotempty->`ENOTEMPTY|ewhene=enotsock->`ENOTSOCK|ewhene=enotsup->`ENOTSUP|ewhene=enotty->`ENOTTY|ewhene=eperm->`EPERM|ewhene=epipe->`EPIPE|ewhene=eproto->`EPROTO|ewhene=eprotonosupport->`EPROTONOSUPPORT|ewhene=eprototype->`EPROTOTYPE|ewhene=erange->`ERANGE|ewhene=erofs->`EROFS|ewhene=eshutdown->`ESHUTDOWN|ewhene=espipe->`ESPIPE|ewhene=esrch->`ESRCH|ewhene=etimedout->`ETIMEDOUT|ewhene=etxtbsy->`ETXTBSY|ewhene=exdev->`EXDEV|ewhene=unknown->`UNKNOWN|ewhene=eof->`EOF|ewhene=enxio->`ENXIO|ewhene=emlink->`EMLINK|_->`UNKNOWNletresult_from_cerror_code=Result.Error(from_cerror_code)lettranslate_sys_errorsys_error_code=C.Functions.Error.translate_sys_errorsys_error_code|>from_cleterror_string_genericc_functionerror=letlength=256inletbuffer=Bytes.createlengthinc_function(to_cerror)(Ctypes.ocaml_bytes_startbuffer)length;letlength=Bytes.indexbuffer'\000'inBytes.sub_stringbuffer0lengthletstrerror=error_string_genericC.Functions.Error.strerror_rleterr_name=error_string_genericC.Functions.Error.err_name_rletexception_handler=refbeginfunexn->prerr_endline(Printexc.to_stringexn);Printexc.print_backtracestderr;exit2endletset_on_unhandled_exceptionf=exception_handler:=fletunhandled_exceptionexn=!exception_handlerexnletcatch_exceptionsfv=tryfvwithexn->unhandled_exceptionexnletto_resultsuccess_valueerror_code=iferror_code>=0thenResult.Oksuccess_valueelseResult.Error(from_cerror_code)letto_result_lazyget_success_valueerror_code=iferror_code>=0thenResult.Ok(get_success_value())elseResult.Error(from_cerror_code)letclampcode=ifcode>=0then0elsecode