first commit

This commit is contained in:
zapashcanon 2019-09-14 02:24:23 +02:00
commit ad8f6bc9c8
Signed by: zapashcanon
GPG Key ID: 8981C3C62D1D28F1
12 changed files with 119 additions and 0 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
_build/
*.install
*.merlin
*.opam

3
CHANGES.md Normal file
View File

@ -0,0 +1,3 @@
## 0.1.0 - 2019-09-14
First release

8
LICENSE.md Normal file
View File

@ -0,0 +1,8 @@
The ISC License (ISC)
=====================
Copyright © 2019, Léo Andrès
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

31
README.md Normal file
View File

@ -0,0 +1,31 @@
# Exit
Exit is an OCaml library to get exit status as declared in `stdlib.h`. It gives access to the values of `EXIT_SUCCESS` and `EXIT_FAILURE` macros and provides some functions built around them.<Paste>
## Install
```sh
opam install exit
```
## Usage
See [examples].
## Build
```sh
dune build @all
```
## Test
```sh
dune runtest
```
## Changes
See [CHANGES].
## License
See [LICENSE].
[CHANGES]: ./CHANGES.md
[examples]: ./examples/
[LICENSE]: ./LICENSE.md

19
dune-project Normal file
View File

@ -0,0 +1,19 @@
(lang dune 1.11)
(name exit)
(license ISC)
(authors "Léo Andrès <l@ndrs.fr>")
(maintainers "Léo Andrès <l@ndrs.fr>")
(source (uri git://git.zapashcanon.fr/zapashcanon/exit.git))
(bug_reports https://git.zapashcanon.fr/zapashcanon/exit/issues)
(homepage https://git.zapashcanon.fr/zapashcanon/exit/issues)
(generate_opam_files true)
(explicit_js_mode)
(package
(name exit)
(synopsis "An OCaml library to get exit status as declared in `stdlib.h`")
(description "Exit is an OCaml library to get exit status as declared in `stdlib.h`.
It gives access to the values of `EXIT_SUCCESS` and `EXIT_FAILURE` macros and provides some functions built around them.")
(depends
(dune (> 1.11.0))))

3
examples/dune Normal file
View File

@ -0,0 +1,3 @@
(executable
(name print_code)
(libraries exit))

11
examples/print_code.ml Normal file
View File

@ -0,0 +1,11 @@
let _ =
Format.printf "succes code is %d@." Exit.success_code;
Format.printf "failure code is %d@." Exit.failure_code;
if Exit.success_code <> 0 || Exit.failure_code <> 1 then begin
Format.printf "not POSIX !@.";
Exit.failure ()
end;
Exit.success ()

4
src/dune Normal file
View File

@ -0,0 +1,4 @@
(library
(public_name exit)
(wrapped false)
(c_names exit_stubs))

14
src/exit.ml Normal file
View File

@ -0,0 +1,14 @@
external success_code : unit -> int = "get_success_code"
external failure_code : unit -> int = "get_failure_code"
let success_code = success_code ()
let failure_code = failure_code ()
let success () =
exit success_code
let failure () =
exit failure_code
let is_posix =
success_code = 0 && failure_code = 1

14
src/exit_stubs.c Normal file
View File

@ -0,0 +1,14 @@
#include <stdlib.h>
#include <caml/mlvalues.h>
#include <caml/memory.h>
CAMLprim value get_success_code(value unit) {
CAMLparam1(unit);
return Val_int(EXIT_SUCCESS);
}
CAMLprim value get_failure_code(value unit) {
CAMLparam1(unit);
return Val_int(EXIT_FAILURE);
}

3
test/dune Normal file
View File

@ -0,0 +1,3 @@
(test
(name test)
(libraries exit))

5
test/test.ml Normal file
View File

@ -0,0 +1,5 @@
assert (Exit.success_code >= 0);
assert (Exit.failure_code >= 0);
assert (Exit.success_code <= 255);
assert (Exit.failure_code <= 255);
assert (Exit.success_code <> Exit.failure_code);