Browse Source

first commit

tags/0.0.1
zapashcanon 1 year ago
commit
ad8f6bc9c8
Signed by: zapashcanon GPG Key ID: 8981C3C62D1D28F1
12 changed files with 119 additions and 0 deletions
  1. +4
    -0
      .gitignore
  2. +3
    -0
      CHANGES.md
  3. +8
    -0
      LICENSE.md
  4. +31
    -0
      README.md
  5. +19
    -0
      dune-project
  6. +3
    -0
      examples/dune
  7. +11
    -0
      examples/print_code.ml
  8. +4
    -0
      src/dune
  9. +14
    -0
      src/exit.ml
  10. +14
    -0
      src/exit_stubs.c
  11. +3
    -0
      test/dune
  12. +5
    -0
      test/test.ml

+ 4
- 0
.gitignore View File

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

+ 3
- 0
CHANGES.md View File

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

+ 8
- 0
LICENSE.md 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
- 0
README.md 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
- 0
dune-project 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
- 0
examples/dune View File

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

+ 11
- 0
examples/print_code.ml 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
- 0
src/dune View File

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

+ 14
- 0
src/exit.ml 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
- 0
src/exit_stubs.c 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
- 0
test/dune View File

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

+ 5
- 0
test/test.ml 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);

Loading…
Cancel
Save