]> 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 int getpagesize(void)
70 {
71   return L4_PAGESIZE;
72 }
73
74 pid_t getpid(void)
75 {
76   return 2;
77 }
78
79 pid_t fork(void)
80 {
81   printf("Unimplemented: fork()\n");
82   errno = -ENOMEM;
83   return -1;
84 }
85
86 int daemon(int nochdir, int noclose)
87 {
88   printf("Unimplemented: daemon(%d, %d)\n", nochdir, noclose);
89   errno = -ENOMEM;
90   return -1;
91 }
92
93 int kill(pid_t pid, int sig)
94 {
95   printf("Unimplemented: kill(%d, %d)\n", pid, sig);
96   errno = -EINVAL;
97   return -1;
98 }
99
100 #include <time.h>
101
102 int timer_delete(timer_t timer_id)
103 {
104   printf("Unimplemented: %s(timer_id)\n", __func__);
105   (void)timer_id;
106   errno = -EINVAL;
107   return -1;
108 }
109
110 int timer_gettime(timer_t timer_id, struct itimerspec *setting)
111 {
112   printf("Unimplemented: %s(timer_id)\n", __func__);
113   (void)timer_id;
114   (void)setting;
115   errno = -EINVAL;
116   return -1;
117 }
118
119 int timer_settime(timer_t timer_id, int __flags,
120                   __const struct itimerspec *__restrict __value,
121                   struct itimerspec *__restrict __ovalue)
122 {
123   printf("Unimplemented: %s(timer_id)\n", __func__);
124   (void)timer_id;
125   (void)__value;
126   (void)__ovalue;
127   (void)__flags;
128   errno = -EINVAL;
129   return -1;
130 }
131
132 int timer_create (clockid_t __clock_id,
133                   struct sigevent *__restrict __evp,
134                   timer_t *__restrict __timerid)
135 {
136   printf("Unimplemented: %s(clock_id)\n", __func__);
137   (void)__clock_id;
138   (void)__evp;
139   (void)__timerid;
140   errno = -EINVAL;
141   return -1;
142 }
143
144 #include <sys/times.h>
145
146 clock_t times(struct tms *buf)
147 {
148   // some arbitrary values
149   buf->tms_utime = (clock_t)l4re_kip()->clock;
150   buf->tms_stime = 10;
151   buf->tms_cutime = 0;
152   buf->tms_cstime = 0;
153   return (clock_t)l4re_kip()->clock;
154 }
155
156
157 #include <stdlib.h>
158 char *ptsname(int fd);
159 char *ptsname(int fd)
160 {
161   printf("unimplemented: %s(%d)\n", __func__, fd);
162   return "unimplemented-ptsname";
163 }
164
165 #include <pty.h>
166
167 int setuid(uid_t uid)
168 {
169   printf("Unimplemented: %s(%d)\n", __func__, uid);
170   return -1;
171 }
172
173 pid_t setsid(void)
174 {
175   printf("Unimplemented: %s()\n", __func__);
176   return -1;
177 }
178
179 int setgid(gid_t gid)
180 {
181   printf("Unimplemented: %s(%d)\n", __func__, gid);
182   return -1;
183 }
184
185
186 mode_t umask(mode_t mask)
187 {
188   printf("Unimplemented: %s(%d)\n", __func__, mask);
189   return 0;
190 }
191
192 int pipe(int pipefd[2])
193 {
194   printf("Unimplemented: %s()\n", __func__);
195   printf("    Caller %p\n", __builtin_return_address(0));
196   (void)pipefd;
197   errno = EINVAL;
198   return -1;
199 }
200
201 #include <sys/wait.h>
202 pid_t waitpid(pid_t pid, int *status, int options)
203 {
204   printf("Unimplemented: %s(%d)\n", __func__, pid);
205   (void)status;
206   (void)options;
207   errno = EINVAL;
208   return -1;
209 }
210
211 FILE *popen(const char *command, const char *type)
212 {
213   printf("Unimplemented: %s(%s, %s)\n", __func__, command, type);
214   return NULL;
215 }
216
217 int pclose(FILE *stream)
218 {
219   printf("Unimplemented: %s(..)\n", __func__);
220   (void)stream;
221   return 0;
222 }
223
224
225
226 int execv(const char *path, char *const argv[])
227 {
228   printf("Unimplemented: %s(%s)\n", __func__, path);
229   (void)argv;
230   errno = EINVAL;
231   return -1;
232 }
233
234 int execvp(const char *file, char *const argv[])
235 {
236   printf("Unimplemented: %s(%s)\n", __func__, file);
237   (void)argv;
238   errno = EINVAL;
239   return -1;
240 }
241
242 int execve(const char *filename, char *const argv[],
243            char *const envp[])
244 {
245   printf("Unimplemented: %s(%s)\n", __func__, filename);
246   (void)argv;
247   (void)envp;
248   errno = EINVAL;
249   return -1;
250 }
251
252 int execl(const char *path, const char *arg, ...)
253 {
254   printf("Unimplemented: %s(%s)\n", __func__, path);
255   (void)arg;
256   errno = EINVAL;
257   return -1;
258 }
259
260 int execlp(const char *file, const char *arg, ...)
261 {
262   printf("Unimplemented: %s(%s)\n", __func__, file);
263   (void)arg;
264   errno = EINVAL;
265   return -1;
266 }
267
268 long pathconf(const char *path, int name)
269 {
270   printf("Unimplemented: %s(%s, %d)\n", __func__, path, name);
271   errno = EINVAL;
272   return -1;
273 }
274
275
276
277
278
279 #include <termios.h>
280 int cfsetispeed(struct termios *termios_p, speed_t speed)
281 {
282   printf("Unimplemented: %s()\n", __func__);
283   (void)termios_p; (void)speed;
284   errno = EINVAL;
285   return -1;
286 }
287
288 int cfsetospeed(struct termios *termios_p, speed_t speed)
289 {
290   printf("Unimplemented: %s()\n", __func__);
291   (void)termios_p; (void)speed;
292   errno = EINVAL;
293   return -1;
294 }
295
296 int tcsendbreak(int fd, int duration)
297 {
298   printf("Unimplemented: %s()\n", __func__);
299   (void)fd; (void)duration;
300   errno = EINVAL;
301   return -1;
302 }
303
304 void cfmakeraw(struct termios *termios_p)
305 {
306   printf("Unimplemented: %s()\n", __func__);
307   (void)termios_p;
308 }
309
310 int openpty(int *amaster, int *aslave, char *name,
311             struct termios *termp, struct winsize *winp)
312 {
313   printf("Unimplemented: %s(.., .., %s, ..)\n", __func__, name);
314   (void)amaster; (void)aslave;
315   (void)termp; (void)winp;
316   errno = EINVAL;
317   return -1;
318 }
319
320
321
322
323
324 uid_t getuid(void) { return 123; }
325 uid_t getgid(void) { return 123; }
326 uid_t geteuid(void) { return 123; }
327 uid_t getegid(void) { return 123; }
328 pid_t getpgrp(void) { return 7; }
329 pid_t getppid(void) { return 122; }
330
331 int setpgid(pid_t pid, pid_t pgid)
332 {
333   printf("Unimplemented: %s(%d, %d)\n", __func__, pid, pgid);
334   errno = EPERM;
335   return -1;
336 }
337
338
339 int getgroups(int size, gid_t list[])
340 {
341   (void)size; (void)list;
342   printf("Unimplemented: %s()\n", __func__);
343   errno = EPERM;
344   return -1;
345 }
346
347 pid_t wait3(int *status, int options, struct rusage *rusage)
348 {
349   printf("Unimplemented: %s(%p, %d, %p)\n", __func__,
350          status, options, rusage);
351
352   errno = EPERM;
353   return -1;
354 }
355
356
357
358 #include <sys/types.h>
359
360 int getrlimit(__rlimit_resource_t resource, struct rlimit *rlim)
361 {
362   printf("Unimplemented: %s(%d, %p)\n", __func__, resource, rlim);
363   errno = EINVAL;
364   return -1;
365 }
366
367 int setrlimit(__rlimit_resource_t resource, const struct rlimit *rlim)
368 {
369   printf("Unimplemented: %s(%d, %p)\n", __func__,
370          resource, rlim);
371   errno = EINVAL;
372   return -1;
373 }
374
375 #ifdef __USE_LARGEFILE64
376 int setrlimit64(__rlimit_resource_t resource, const struct rlimit64 *rlim)
377 {
378   printf("Unimplemented: %s(%d, %p)\n", __func__,
379          resource, rlim);
380   errno = EINVAL;
381   return -1;
382 }
383 #else
384 #warning No large-file support enabled?
385 #endif
386
387 char *getpass( const char *prompt)
388 {
389   printf("This would be the prompt: '%s', delivering something static\n",
390          prompt);
391   return "THE FAMOUS PASSWORD";
392 }
393
394 int system(const char *path)
395 {
396   (void)path;
397   errno = EINVAL;
398   return -1;
399 }
400
401 #include <string.h>
402
403 int uname(struct utsname *u)
404 {
405   strncpy(u->sysname, "Fiasco.OC/L4Re", sizeof(u->sysname));
406   u->sysname[sizeof(u->sysname) - 1] = 0;
407
408   strncpy(u->nodename, "localhost", sizeof(u->nodename));
409   u->nodename[sizeof(u->nodename) - 1] = 0;
410
411   strncpy(u->release, "L4Re", sizeof(u->release));
412   u->release[sizeof(u->release) - 1] = 0;
413
414   strncpy(u->version, "0.x", sizeof(u->version));
415   u->version[sizeof(u->version) - 1] = 0;
416
417 #ifdef ARCH_arm
418   strncpy(u->machine, "arm", sizeof(u->machine));
419 #elif defined(ARCH_x86)
420   strncpy(u->machine, "i686", sizeof(u->machine));
421 #elif defined(ARCH_amd64)
422   strncpy(u->machine, "x86_64", sizeof(u->machine));
423 #elif defined(ARCH_ppc32)
424   strncpy(u->machine, "ppc32", sizeof(u->machine));
425 #else
426 #error Add your arch.
427 #endif
428   u->machine[sizeof(u->machine) - 1] = 0;
429
430   return 0;
431 }
432
433 #include <sys/shm.h>
434
435 int shmget(key_t key, size_t size, int shmflg)
436 {
437   printf("%s(%d, %zd, %d)\n", __func__, key, size, shmflg);
438   errno = ENOSYS;
439   return -1;
440 }
441
442 void *shmat(int shmid, const void *shmaddr, int shmflg)
443 {
444   printf("%s(%d, %p, %d)\n", __func__, shmid, shmaddr, shmflg);
445   errno = ENOSYS;
446   return (void *)-1;
447 }
448
449 int shmctl(int shmid, int cmd, struct shmid_ds *buf)
450 {
451   printf("%s(%d, %d, %p)\n", __func__, shmid, cmd, buf);
452   errno = ENOSYS;
453   return -1;
454 }
455
456 int shmdt(const void *shmaddr)
457 {
458   printf("%s(%p)\n", __func__, shmaddr);
459   errno = ENOSYS;
460   return -1;
461 }