Cthulhu  0.2.10
Cthulhu compiler collection
init.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: LGPL-3.0-only
2 
3 #include "os/core.h"
4 
5 #include <limits.h>
6 #include <stdlib.h>
7 #include <unistd.h>
8 #include <pthread.h>
9 
10 static long gMaxNameLength = 0;
11 static long gMaxPathLength = 0;
12 
13 CT_LOCAL size_t impl_maxname(void)
14 {
15  return gMaxNameLength;
16 }
17 
18 CT_LOCAL size_t impl_maxpath(void)
19 {
20  return gMaxPathLength;
21 }
22 
23 CT_LOCAL void impl_init(void)
24 {
25  long path = pathconf(".", _PC_PATH_MAX);
26  if (path < 0)
27  {
28  // best guess if pathconf() fails
29  // TODO: should there be a way to notify the user that the path length is unknown?
30  gMaxPathLength = PATH_MAX;
31  }
32  else
33  {
34  gMaxPathLength = path;
35  }
36 
37  long name = pathconf(".", _PC_NAME_MAX);
38  if (name < 0)
39  {
40  // best guess if pathconf() fails
41  gMaxNameLength = NAME_MAX;
42  }
43  else
44  {
45  gMaxNameLength = name;
46  }
47 }
48 
50 {
51  exit(code); // NOLINT(concurrency-mt-unsafe)
52 }
53 
55 {
56  pthread_exit((void*)(intptr_t)status);
57 }
58 
59 CT_LOCAL void impl_abort(void)
60 {
61  abort(); // NOLINT(concurrency-mt-unsafe)
62 }
int os_exitcode_t
program exit code
Definition: core.h:67
#define CT_LOCAL
Definition: compiler.h:166
unsigned os_status_t
thread return code
Definition: core.h:71
CT_LOCAL size_t impl_maxpath(void)
Definition: init.c:18
CT_LOCAL void impl_thread_exit(os_status_t status)
Definition: init.c:54
CT_LOCAL size_t impl_maxname(void)
Definition: init.c:13
CT_LOCAL void impl_init(void)
Definition: init.c:23
CT_LOCAL void impl_abort(void)
Definition: init.c:59
CT_LOCAL void impl_exit(os_exitcode_t code)
Definition: init.c:49