]> rtime.felk.cvut.cz Git - lincan.git/blob - embedded/arch/arm/generic/libs/misc/system_stub.c
24fa2f9677a4f35d886d4906b980fc509bdc69d5
[lincan.git] / embedded / arch / arm / generic / libs / misc / system_stub.c
1 /* Support files for GNU libc.  Files in the system namespace go here.
2    Files in the C namespace (ie those that do not start with an
3    underscore) go in .c.  */
4
5 #include <sys/types.h>
6 #include <sys/stat.h>
7 #include <sys/fcntl.h>
8 #include <stdio.h>
9 #include <time.h>
10 #include <sys/time.h>
11 #include <sys/times.h>
12 #include <errno.h>
13 #include <reent.h>
14 #include <system_def.h>
15
16 /* Register name faking - works in collusion with the linker.  */
17 register char * stack_ptr asm ("sp");
18
19 system_stub_ops_t system_stub_ops;
20
21 int
22 _read (int file,
23        char * ptr,
24        int len)
25 {
26   if(!system_stub_ops.read)
27     return -1;
28   return system_stub_ops.read(file,ptr,len);
29 }
30
31 int
32 _write (int    file,
33         char * ptr,
34         int    len)
35 {
36   if(!system_stub_ops.write)
37     return len;
38   return system_stub_ops.write(file,ptr,len);
39 }
40
41
42 int
43 _lseek (int file,
44         int pos,
45         int dir)
46 {
47   if(!system_stub_ops.lseek)
48     return -1;
49   return system_stub_ops.lseek(file,pos,dir);
50 }
51
52 int
53 _open (const char * path,
54        int          flags,
55        ...)
56 {
57   if(!system_stub_ops.open)
58     return -1;
59   return system_stub_ops.open(path,flags,0);
60 }
61
62 int
63 _close (int file)
64 {
65   if(!system_stub_ops.close)
66     return -1;
67   return system_stub_ops.close(file);
68 }
69
70 typedef int (local_call_t)(void);
71
72 void
73 _exit (int n)
74 {
75   ((local_call_t*)0)();
76   while(1);
77 }
78
79 int
80 _kill (int n, int m)
81 {
82   return -1;
83 }
84
85 int
86 _getpid (int n)
87 {
88   return 1;
89 }
90
91
92 caddr_t
93 _sbrk (int incr)
94 {
95   extern char   end asm ("end");        /* Defined by the linker.  */
96   static char   *heap_end;
97   char *        prev_heap_end;
98
99   incr=(incr+3) & ~3;
100
101   if (heap_end == NULL)
102     heap_end = & end;
103   
104   prev_heap_end = heap_end;
105     
106   if (heap_end + incr > stack_ptr)
107     {
108       /* Some of the libstdc++-v3 tests rely upon detecting
109          out of memory errors, so do not abort here.  */
110 #if 0
111       extern void abort (void);
112
113       _write (1, "_sbrk: Heap and stack collision\n", 32);
114       
115       abort ();
116 #else
117       errno = ENOMEM;
118       return (caddr_t) -1;
119 #endif
120     }
121   
122   heap_end += incr;
123
124   return (caddr_t) prev_heap_end;
125 }
126
127 int
128 _fstat (int file, struct stat * st)
129 {
130   return -1;
131 }
132
133 int _stat (const char *fname, struct stat *st)
134 {
135   return -1;
136 }
137
138 int
139 _link (void)
140 {
141   return -1;
142 }
143
144 int
145 _unlink (void)
146 {
147   return -1;
148 }
149
150 void
151 _raise (void)
152 {
153   return;
154 }
155
156 int
157 _gettimeofday (struct timeval * tp, struct timezone * tzp)
158 {
159
160   if(tp) 
161     {
162       tp->tv_sec = 0;
163       tp->tv_usec = 0;
164     }
165   /* Return fixed data for the timezone.  */
166   if (tzp)
167     {
168       tzp->tz_minuteswest = 0;
169       tzp->tz_dsttime = 0;
170     }
171
172   return 0;
173 }
174
175 /* Return a clock that ticks at 100Hz.  */
176 clock_t 
177 _times (struct tms * tp)
178 {
179   clock_t timeval = 0;
180   
181   if (tp)
182     {
183       tp->tms_utime  = timeval; /* user time */
184       tp->tms_stime  = 0;       /* system time */
185       tp->tms_cutime = 0;       /* user time, children */
186       tp->tms_cstime = 0;       /* system time, children */
187     }
188   
189   return timeval;
190 };
191
192
193 int
194 isatty (int fd)
195 {
196   return 1;
197 }
198
199 int
200 _system (const char *s)
201 {
202   return -1;
203 }
204
205 int
206 _rename (const char * oldpath, const char * newpath)
207 {
208   return -1;
209 }