rework langinfo code for ABI compat and for use by time code
[musl] / src / process / fork.c
1 #include <unistd.h>
2 #include <string.h>
3 #include "syscall.h"
4 #include "libc.h"
5 #include "pthread_impl.h"
6
7 static void dummy(int x)
8 {
9 }
10
11 weak_alias(dummy, __fork_handler);
12
13 pid_t fork(void)
14 {
15         pid_t ret;
16         __fork_handler(-1);
17         ret = syscall(SYS_fork);
18         if (libc.main_thread && !ret) {
19                 pthread_t self = __pthread_self();
20                 self->tid = self->pid = syscall(SYS_getpid);
21                 memset(&self->robust_list, 0, sizeof self->robust_list);
22                 libc.threads_minus_1 = 0;
23                 libc.main_thread = self;
24         }
25         __fork_handler(!ret);
26         return ret;
27 }