AcesNative+Usermode - libacessnative "works" (for some definitions)
[tpg/acess2.git] / AcessNative / libacess-native.so_src / main.c
1 /*
2  */
3 #include <stdarg.h>
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include <string.h>
7
8 extern int      giSyscall_ClientID;
9 extern void     Request_Preinit(void);
10 extern int      acess__SysOpen(const char *Path, unsigned int flags);
11
12 #ifdef __WINDOWS__
13 int DllMain(void)
14 {
15         fprintf(stderr, "TODO: Windows libacessnative setup\n");
16         return 0;
17 }
18
19 #endif
20
21 #ifdef __linux__
22 int __attribute__ ((constructor)) libacessnative_init(void);
23
24 int libacessnative_init(void)
25 {
26         Request_Preinit();
27
28         const char *preopens = getenv("AN_PREOPEN");
29         if( preopens )
30         {
31                 while( *preopens )
32                 {
33                         const char *splitter = strchr(preopens, ':');
34                         size_t  len;
35                         if( !splitter ) {
36                                 len = strlen(preopens);
37                         }
38                         else {
39                                 len = splitter - preopens;
40                         }
41                         char path[len+1];
42                         memcpy(path, preopens, len);
43                         path[len] = 0;
44                         int fd = acess__SysOpen(path, 6);       // WRITE,READ,no EXEC
45                         if( fd == -1 ) {
46                                 fprintf(stderr, "Unable to preopen '%s'\n", path);
47                         }
48                         
49                         if( !splitter )
50                                 break;
51                         preopens = splitter + 1;
52                 }
53         }
54
55 //      if( !getenv("ACESSNATIVE_ID")
56         
57         return 0;
58 }
59 #endif
60
61
62 void Debug(const char *format, ...)
63 {
64         va_list args;
65         printf("Debug: ");
66         va_start(args, format);
67         vfprintf(stdout, format, args);
68         va_end(args);
69         printf("\n");
70 }
71
72 void Warning(const char *format, ...)
73 {
74         va_list args;
75         printf("Warning: ");
76         va_start(args, format);
77         vfprintf(stdout, format, args);
78         va_end(args);
79         printf("\n");
80 }
81
82 void __libc_csu_fini()
83 {
84 }
85
86 void __libc_csu_init()
87 {
88 }
89

UCC git Repository :: git.ucc.asn.au