File: stdcompat__stubs.c.in

package info (click to toggle)
ocaml-stdcompat 20~git20240529-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 7,540 kB
  • sloc: ml: 34,099; sh: 861; makefile: 249
file content (112 lines) | stat: -rw-r--r-- 2,489 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include <string.h>
#include "stdcompat.h"

@C_BEGIN_FROM_5_0_0@
void stdcompat_dummy_symbol()
{
  /* If the library is empty, then the following error message appears on macOS:
     ld: archive has no table of contents file './libtest_prog_stubs.a' for
     architecture arm64

     One solution is to execute `ranlib libtest_prog_stubs.a` after `ocamlmklib`
     and before `ocamlopt` use the library, but I don't know how to make dune
     execute the command.

     Another solution is to export a dummy symbol!
  */
}
@C_END_FROM_5_0_0@

@C_BEGIN_BEFORE_4_12_0@
@C_BEGIN_FROM_4_04_0@
#include <caml/major_gc.h>
@C_END_FROM_4_04_0@
#define CAML_INTERNALS
#include <caml/memory.h>
@C_BEGIN_FROM_4_04_0@
#include <caml/sys.h>
#include <caml/osdeps.h>
@C_END_FROM_4_04_0@
@C_BEGIN_BEFORE_4_04_0@
@C_BEGIN_BEFORE_3_08_0@
CAMLextern void sys_error (value);
#define caml_sys_error sys_error
@C_END_BEFORE_3_08_0@
@C_BEGIN_FROM_3_08_0@
CAMLextern void caml_sys_error (value);
@C_END_FROM_3_08_0@
@C_END_BEFORE_4_04_0@
#ifdef _WIN32
#include <direct.h>
#else
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#endif

@C_BEGIN_BEFORE_3_08_0@
#define caml_alloc_string alloc_string
@C_END_BEFORE_3_08_0@

CAMLprim value caml_sys_mkdir(value path, value perm)
{
  CAMLparam2(path, perm);
  int ret;
@C_BEGIN_FROM_4_06_0@
  char_os * p = caml_stat_strdup_to_os(String_val(path));
  #ifdef _WIN32
    ret = _wmkdir(p);
  #else
    ret = mkdir(p, Int_val(perm));
  #endif
  caml_stat_free(p);
@C_END_FROM_4_06_0@
@C_BEGIN_BEFORE_4_06_0@
  char * p;
  p = String_val(path);
  #ifdef _WIN32
    ret = _mkdir(p);
  #else
    ret = mkdir(p, Int_val(perm));
  #endif
@C_END_BEFORE_4_06_0@
  if (ret == -1) caml_sys_error(path);
  CAMLreturn(Val_unit);
}

CAMLprim value caml_sys_rmdir(value path)
{
  CAMLparam1(path);
  int ret;
@C_BEGIN_FROM_4_06_0@
  char_os * p = caml_stat_strdup_to_os(String_val(path));
  #ifdef _WIN32
    ret = _wrmdir(p);
  #else
    ret = rmdir(p);
  #endif
  caml_stat_free(p);
@C_END_FROM_4_06_0@
@C_BEGIN_BEFORE_4_06_0@
  char * p;
  p = String_val(path);
  #ifdef _WIN32
    ret = _rmdir(p);
  #else
    ret = rmdir(p);
  #endif
@C_END_BEFORE_4_06_0@
  if (ret == -1) caml_sys_error(path);
  CAMLreturn(Val_unit);
}
@C_END_BEFORE_4_12_0@

@C_BEGIN_BEFORE_4_06_0@
value
caml_alloc_initialized_string(mlsize_t len, const char *p)
{
  value result = caml_alloc_string(len);
  memcpy((char *)String_val(result), p, len);
  return result;
}
@C_END_BEFORE_4_06_0@