Browse Source

first commit

master
zapashcanon 2 years ago
commit
ad8f6bc9c8
Signed by: zapashcanon GPG Key ID: 8981C3C62D1D28F1
  1. 4
      .gitignore
  2. 3
      CHANGES.md
  3. 8
      LICENSE.md
  4. 31
      README.md
  5. 19
      dune-project
  6. 3
      examples/dune
  7. 11
      examples/print_code.ml
  8. 4
      src/dune
  9. 14
      src/exit.ml
  10. 14
      src/exit_stubs.c
  11. 3
      test/dune
  12. 5
      test/test.ml

4
.gitignore

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

3
CHANGES.md

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

8
LICENSE.md

@ -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

@ -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

@ -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

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

11
examples/print_code.ml

@ -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

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

14
src/exit.ml

@ -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

@ -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

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

5
test/test.ml

@ -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);
Loading…
Cancel
Save