]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/libc_backends/lib/misc/misc.c
update
[l4.git] / l4 / pkg / libc_backends / lib / misc / misc.c
1 /*
2  * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
3  *               Alexander Warg <warg@os.inf.tu-dresden.de>
4  *     economic rights: Technische Universität Dresden (Germany)
5  * This file is part of TUD:OS and distributed under the terms of the
6  * GNU Lesser General Public License 2.1.
7  * Please see the COPYING-LGPL-2.1 file for details.
8  */
9 #ifndef _GNU_SOURCE
10 #define _GNU_SOURCE
11 #endif
12 #include <stdio.h>
13 #include <unistd.h>
14 #include <errno.h>
15 #include <stdlib.h>
16 #include <signal.h>
17 #include <sys/stat.h>
18 #include <sys/mman.h>
19 #include <l4/sys/consts.h>
20 #include <l4/re/env.h>
21 #include <sys/utsname.h>
22 #include <sys/resource.h>
23
24
25 int __ctype_b_loc(void);
26 int __sched_cpucount(void);
27 int getloadavg(double loadavg[], int nelem);
28
29 /* Implementations */
30 int __ctype_b_loc(void)
31 {
32   printf("%s: implement me \n", __func__);
33   return 0;
34 }
35
36 int __sched_cpucount(void)
37 {
38   return 4; // just some number
39 }
40
41 long sysconf(int name)
42 {
43   switch (name)
44   {
45   case _SC_NPROCESSORS_ONLN:
46     return __sched_cpucount();
47   case _SC_PAGE_SIZE:
48     return L4_PAGESIZE;
49   case _SC_CLK_TCK:
50     return 1000;
51   case _SC_MONOTONIC_CLOCK:
52     return 200112L;
53   default:
54     break;
55   }
56   printf("%s: unknown command, name=%d\n", __func__, name);
57   return 0;
58 }
59
60 int getloadavg(double loadavg[], int nelem)
61 {
62   (void)nelem;
63   loadavg[0] = 0.7;
64   loadavg[1] = 0.7;
65   loadavg[2] = 0.7;
66   return 3;
67 }
68
69 pid_t getpid(void)
70 {
71   return 2;
72 }
73
74 pid_t fork(void)
75 {
76   printf("Unimplemented: fork()\n");
77   errno = -ENOMEM;
78   return -1;
79 }
80
81 int daemon(int nochdir, int noclose)
82 {
83   printf("Unimplemented: daemon(%d, %d)\n", nochdir, noclose);
84   errno = -ENOMEM;
85   return -1;
86 }
87
88 int kill(pid_t pid, int sig)
89 {
90   printf("Unimplemented: kill(%d, %d)\n", pid, sig);
91   errno = -EINVAL;
92   return -1;
93 }
94
95 #include <time.h>
96
97 int timer_delete(timer_t timer_id)
98 {
99   printf("Unimplemented: %s(timer_id)\n", __func__);
100   (void)timer_id;
101   errno = -EINVAL;
102   return -1;
103 }
104
105 int timer_gettime(timer_t timer_id, struct itimerspec *setting)
106 {
107   printf("Unimplemented: %s(timer_id)\n", __func__);
108   (void)timer_id;
109   (void)setting;
110   errno = -EINVAL;
111   return -1;
112 }
113
114 int timer_settime(timer_t timer_id, int __flags,
115                   __const struct itimerspec *__restrict __value,
116                   struct itimerspec *__restrict __ovalue)
117 {
118   printf("Unimplemented: %s(timer_id)\n", __func__);
119   (void)timer_id;
120   (void)__value;
121   (void)__ovalue;
122   (void)__flags;
123   errno = -EINVAL;
124   return -1;
125 }
126
127 int timer_create (clockid_t __clock_id,
128                   struct sigevent *__restrict __evp,
129                   timer_t *__restrict __timerid)
130 {
131   printf("Unimplemented: %s(clock_id)\n", __func__);
132   (void)__clock_id;
133   (void)__evp;
134   (void)__timerid;
135   errno = -EINVAL;
136   return -1;
137 }
138
139 #include <sys/times.h>
140
141 clock_t times(struct tms *buf)
142 {
143   // some arbitrary values
144   buf->tms_utime = (clock_t)l4_kip_clock(l4re_kip());
145   buf->tms_stime = 10;
146   buf->tms_cutime = 0;
147   buf->tms_cstime = 0;
148   return (clock_t)l4_kip_clock(l4re_kip());
149 }
150
151
152 #include <stdlib.h>
153 char *ptsname(int fd);
154 char *ptsname(int fd)
155 {
156   printf("unimplemented: %s(%d)\n", __func__, fd);
157   return "unimplemented-ptsname";
158 }
159
160 #include <pty.h>
161
162 int setuid(uid_t uid)
163 {
164   printf("Unimplemented: %s(%d)\n", __func__, uid);
165   return -1;
166 }
167
168 pid_t setsid(void)
169 {
170   printf("Unimplemented: %s()\n", __func__);
171   return -1;
172 }
173
174 int setgid(gid_t gid)
175 {
176   printf("Unimplemented: %s(%d)\n", __func__, gid);
177   return -1;
178 }
179
180
181 mode_t umask(mode_t mask)
182 {
183   printf("Unimplemented: %s(%d)\n", __func__, mask);
184   return 0;
185 }
186
187 int pipe(int pipefd[2])
188 {
189   printf("Unimplemented: %s()\n", __func__);
190   printf("    Caller %p\n", __builtin_return_address(0));
191   (void)pipefd;
192   errno = EINVAL;
193   return -1;
194 }
195
196 #include <sys/wait.h>
197 pid_t waitpid(pid_t pid, int *status, int options)
198 {
199   printf("Unimplemented: %s(%d)\n", __func__, pid);
200   (void)status;
201   (void)options;
202   errno = EINVAL;
203   return -1;
204 }
205
206 FILE *popen(const char *command, const char *type)
207 {
208   printf("Unimplemented: %s(%s, %s)\n", __func__, command, type);
209   return NULL;
210 }
211
212 int pclose(FILE *stream)
213 {
214   printf("Unimplemented: %s(..)\n", __func__);
215   (void)stream;
216   return 0;
217 }
218
219
220
221 int execv(const char *path, char *const argv[])
222 {
223   printf("Unimplemented: %s(%s)\n", __func__, path);
224   (void)argv;
225   errno = EINVAL;
226   return -1;
227 }
228
229 int execvp(const char *file, char *const argv[])
230 {
231   printf("Unimplemented: %s(%s)\n", __func__, file);
232   (void)argv;
233   errno = EINVAL;
234   return -1;
235 }
236
237 int execve(const char *filename, char *const argv[],
238            char *const envp[])
239 {
240   printf("Unimplemented: %s(%s)\n", __func__, filename);
241   (void)argv;
242   (void)envp;
243   errno = EINVAL;
244   return -1;
245 }
246
247 int execl(const char *path, const char *arg, ...)
248 {
249   printf("Unimplemented: %s(%s)\n", __func__, path);
250   (void)arg;
251   errno = EINVAL;
252   return -1;
253 }
254
255 int execlp(const char *file, const char *arg, ...)
256 {
257   printf("Unimplemented: %s(%s)\n", __func__, file);
258   (void)arg;
259   errno = EINVAL;
260   return -1;
261 }
262
263 long fpathconf(int fd, int name)
264 {
265   printf("Unimplemented: %s(%d, %d)\n", __func__, fd, name);
266   errno = EINVAL;
267   return -1;
268 }
269
270 long pathconf(const char *path, int name)
271 {
272   printf("Unimplemented: %s(%s, %d)\n", __func__, path, name);
273   errno = EINVAL;
274   return -1;
275 }
276
277
278
279
280
281 #include <termios.h>
282
283 int tcsendbreak(int fd, int duration)
284 {
285   printf("Unimplemented: %s()\n", __func__);
286   (void)fd; (void)duration;
287   errno = EINVAL;
288   return -1;
289 }
290
291 void cfmakeraw(struct termios *termios_p)
292 {
293   printf("Unimplemented: %s()\n", __func__);
294   (void)termios_p;
295 }
296
297 int openpty(int *amaster, int *aslave, char *name,
298             struct termios *termp, struct winsize *winp)
299 {
300   printf("Unimplemented: %s(.., .., %s, ..)\n", __func__, name);
301   (void)amaster; (void)aslave;
302   (void)termp; (void)winp;
303   errno = EINVAL;
304   return -1;
305 }
306
307
308
309
310
311 uid_t getuid(void) { return 123; }
312 uid_t getgid(void) { return 123; }
313 uid_t geteuid(void) { return 123; }
314 uid_t getegid(void) { return 123; }
315 pid_t getpgrp(void) { return 7; }
316 pid_t getppid(void) { return 122; }
317
318 int setpgid(pid_t pid, pid_t pgid)
319 {
320   printf("Unimplemented: %s(%d, %d)\n", __func__, pid, pgid);
321   errno = EPERM;
322   return -1;
323 }
324
325
326 int getgroups(int size, gid_t list[])
327 {
328   (void)size; (void)list;
329   printf("Unimplemented: %s()\n", __func__);
330   errno = EPERM;
331   return -1;
332 }
333
334 pid_t wait3(int *status, int options, struct rusage *rusage)
335 {
336   printf("Unimplemented: %s(%p, %d, %p)\n", __func__,
337          status, options, rusage);
338
339   errno = EPERM;
340   return -1;
341 }
342
343
344
345 #include <sys/types.h>
346
347 int getrlimit(__rlimit_resource_t resource, struct rlimit *rlim)
348 {
349   printf("Unimplemented: %s(%d, %p)\n", __func__, resource, rlim);
350   errno = EINVAL;
351   return -1;
352 }
353
354 int setrlimit(__rlimit_resource_t resource, const struct rlimit *rlim)
355 {
356   printf("Unimplemented: %s(%d, %p)\n", __func__,
357          resource, rlim);
358   errno = EINVAL;
359   return -1;
360 }
361
362 #ifdef __USE_LARGEFILE64
363 int setrlimit64(__rlimit_resource_t resource, const struct rlimit64 *rlim)
364 {
365   printf("Unimplemented: %s(%d, %p)\n", __func__,
366          resource, rlim);
367   errno = EINVAL;
368   return -1;
369 }
370 #else
371 #warning No large-file support enabled?
372 #endif
373
374 char *getpass( const char *prompt)
375 {
376   printf("This would be the prompt: '%s', delivering something static\n",
377          prompt);
378   return "THE FAMOUS PASSWORD";
379 }
380
381 int system(const char *path)
382 {
383   (void)path;
384   errno = EINVAL;
385   return -1;
386 }
387
388 #include <string.h>
389
390 int uname(struct utsname *u)
391 {
392   strncpy(u->sysname, "Fiasco.OC/L4Re", sizeof(u->sysname));
393   u->sysname[sizeof(u->sysname) - 1] = 0;
394
395   strncpy(u->nodename, "localhost", sizeof(u->nodename));
396   u->nodename[sizeof(u->nodename) - 1] = 0;
397
398   strncpy(u->release, "L4Re", sizeof(u->release));
399   u->release[sizeof(u->release) - 1] = 0;
400
401   strncpy(u->version, "0.x", sizeof(u->version));
402   u->version[sizeof(u->version) - 1] = 0;
403
404 #ifdef ARCH_arm
405   strncpy(u->machine, "arm", sizeof(u->machine));
406 #elif defined(ARCH_x86)
407   strncpy(u->machine, "i686", sizeof(u->machine));
408 #elif defined(ARCH_amd64)
409   strncpy(u->machine, "x86_64", sizeof(u->machine));
410 #elif defined(ARCH_ppc32)
411   strncpy(u->machine, "ppc32", sizeof(u->machine));
412 #elif defined(ARCH_sparc)
413   strncpy(u->machine, "sparcv8", sizeof(u->machine));
414 #else
415 #error Add your arch.
416 #endif
417   u->machine[sizeof(u->machine) - 1] = 0;
418
419   return 0;
420 }
421
422 #include <sys/shm.h>
423
424 int shmget(key_t key, size_t size, int shmflg)
425 {
426   printf("%s(%d, %zd, %d)\n", __func__, key, size, shmflg);
427   errno = ENOSYS;
428   return -1;
429 }
430
431 void *shmat(int shmid, const void *shmaddr, int shmflg)
432 {
433   printf("%s(%d, %p, %d)\n", __func__, shmid, shmaddr, shmflg);
434   errno = ENOSYS;
435   return (void *)-1;
436 }
437
438 int shmctl(int shmid, int cmd, struct shmid_ds *buf)
439 {
440   printf("%s(%d, %d, %p)\n", __func__, shmid, cmd, buf);
441   errno = ENOSYS;
442   return -1;
443 }
444
445 int shmdt(const void *shmaddr)
446 {
447   printf("%s(%p)\n", __func__, shmaddr);
448   errno = ENOSYS;
449   return -1;
450 }
451
452 int getrusage(int who, struct rusage* usage)
453 {
454         (void)who; (void)usage;
455         errno = EINVAL;
456         return -1;
457 }