usb 2.0 support through ios 58, and other usb improvements/corrections. patch by...
[libogc.git] / libogc / newlibc.c
blob0aaae8358bd3fa78513d228715ee49c0bf9fa3ad
1 #include <stdlib.h>
2 #include <string.h>
3 #include <sys/reent.h>
4 #include "sys_state.h"
5 #include "lwp_threads.h"
7 int libc_reentrant;
8 struct _reent libc_globl_reent;
10 extern void _wrapup_reent(struct _reent *);
11 extern void _reclaim_reent(struct _reent *);
13 int __libc_create_hook(lwp_cntrl *curr_thr,lwp_cntrl *create_thr)
15 create_thr->libc_reent = NULL;
16 return 1;
19 int __libc_start_hook(lwp_cntrl *curr_thr,lwp_cntrl *start_thr)
21 struct _reent *ptr;
23 ptr = (struct _reent*)calloc(1,sizeof(struct _reent));
24 if(!ptr) abort();
26 #ifdef __GNUC__
27 _REENT_INIT_PTR((ptr));
28 #endif
30 start_thr->libc_reent = ptr;
31 return 1;
34 int __libc_delete_hook(lwp_cntrl *curr_thr, lwp_cntrl *delete_thr)
36 struct _reent *ptr;
38 if(curr_thr==delete_thr)
39 ptr = _REENT;
40 else
41 ptr = (struct _reent*)delete_thr->libc_reent;
43 if(ptr && ptr!=&libc_globl_reent) {
44 _wrapup_reent(ptr);
45 _reclaim_reent(ptr);
46 free(ptr);
48 delete_thr->libc_reent = 0;
50 if(curr_thr==delete_thr) _REENT = 0;
52 return 1;
55 void __libc_init(int reentrant)
57 libc_globl_reent = (struct _reent)_REENT_INIT((libc_globl_reent));
58 _REENT = &libc_globl_reent;
60 if(reentrant) {
61 __lwp_thread_setlibcreent((void*)&_REENT);
62 libc_reentrant = reentrant;
66 void __libc_wrapup()
68 if(!__sys_state_up(__sys_state_get())) return;
69 if(_REENT!=&libc_globl_reent) {
70 _wrapup_reent(&libc_globl_reent);
71 _REENT = &libc_globl_reent;