1 | /* |
---|
2 | * RTEMS Fake System Calls |
---|
3 | * |
---|
4 | * This file contains "fake" versions of the system call routines |
---|
5 | * which are reference by many libc implementations. Once a routine |
---|
6 | * has been implemented in terms of RTEMS services, it should be |
---|
7 | * taken out of this file. |
---|
8 | * |
---|
9 | * COPYRIGHT (c) 1989-1997. |
---|
10 | * On-Line Applications Research Corporation (OAR). |
---|
11 | * Copyright assigned to U.S. Government, 1994. |
---|
12 | * |
---|
13 | * The license and distribution terms for this file may be |
---|
14 | * found in the file LICENSE in this distribution or at |
---|
15 | * http://www.OARcorp.com/rtems/license.html. |
---|
16 | * |
---|
17 | * $Id$ |
---|
18 | * |
---|
19 | */ |
---|
20 | |
---|
21 | #include <sys/types.h> |
---|
22 | #include <sys/stat.h> |
---|
23 | #include <assert.h> |
---|
24 | #include <errno.h> |
---|
25 | #include <string.h> |
---|
26 | #include <stdio.h> /* only for puts */ |
---|
27 | |
---|
28 | #include <rtems.h> |
---|
29 | #include <rtems/libio.h> |
---|
30 | |
---|
31 | #ifdef RTEMS_NEWLIB |
---|
32 | /* |
---|
33 | * fstat, stat, and isatty must lie consistently and report that everything |
---|
34 | * is a tty or stdout will not be line buffered. |
---|
35 | */ |
---|
36 | |
---|
37 | int __rtems_fstat(int _fd, struct stat* _sbuf) |
---|
38 | { |
---|
39 | #ifdef HAVE_BLKSIZE |
---|
40 | _sbuf->st_blksize = 0; |
---|
41 | #endif |
---|
42 | |
---|
43 | /* |
---|
44 | * For now assume stdin/stdout/stderr are always a TTY line |
---|
45 | * |
---|
46 | * From Eric Norum: |
---|
47 | * |
---|
48 | * The `fix' is not complete. It still doesn't properly handle |
---|
49 | * file descriptors for any files/devices other than the console |
---|
50 | * serial lines..... |
---|
51 | */ |
---|
52 | if (_fd <= 2) { |
---|
53 | _sbuf->st_mode = S_IFCHR; |
---|
54 | } else { |
---|
55 | switch (rtems_file_descriptor_type (_fd)) { |
---|
56 | case RTEMS_FILE_DESCRIPTOR_TYPE_SOCKET: |
---|
57 | _sbuf->st_mode = S_IFSOCK; |
---|
58 | break; |
---|
59 | |
---|
60 | default: |
---|
61 | puts( "__rtems_fstat -- unknown socket type" ); |
---|
62 | assert( 0 ); |
---|
63 | } |
---|
64 | } |
---|
65 | return 0; |
---|
66 | } |
---|
67 | |
---|
68 | int __rtems_isatty(int _fd) |
---|
69 | { |
---|
70 | struct stat st; |
---|
71 | |
---|
72 | if (__rtems_fstat(_fd, &st) < 0) |
---|
73 | return 0; |
---|
74 | return S_ISCHR (st.st_mode); |
---|
75 | } |
---|
76 | |
---|
77 | #if !defined(RTEMS_UNIX) |
---|
78 | int stat( const char *path, struct stat *buf ) |
---|
79 | { |
---|
80 | if ( strncmp( "/dev/", path, 5 ) ) { |
---|
81 | return -1; |
---|
82 | } |
---|
83 | return __rtems_fstat( 0, buf ); |
---|
84 | } |
---|
85 | |
---|
86 | int link( const char *existing, const char *new ) |
---|
87 | { |
---|
88 | /* always fail */ |
---|
89 | return -1; |
---|
90 | } |
---|
91 | |
---|
92 | int unlink( const char *path ) |
---|
93 | { |
---|
94 | /* always fail */ |
---|
95 | return -1; |
---|
96 | } |
---|
97 | |
---|
98 | char *getcwd( char *_buf, size_t _size) |
---|
99 | { |
---|
100 | |
---|
101 | /* assert( FALSE ); */ |
---|
102 | errno = ENOSYS; |
---|
103 | return 0; |
---|
104 | } |
---|
105 | int fork() { |
---|
106 | puts( "fork -- not supported!!!" ); |
---|
107 | assert( 0 ); |
---|
108 | errno = ENOSYS; |
---|
109 | return -1; |
---|
110 | } |
---|
111 | int execv(const char *_path, char * const _argv[] ) { |
---|
112 | puts( "execv -- not supported!!!" ); |
---|
113 | assert( 0 ); |
---|
114 | errno = ENOSYS; |
---|
115 | return -1; |
---|
116 | } |
---|
117 | int wait() { |
---|
118 | puts( "wait -- not supported!!!" ); |
---|
119 | assert( 0 ); |
---|
120 | errno = ENOSYS; |
---|
121 | return -1; |
---|
122 | } |
---|
123 | #endif |
---|
124 | |
---|
125 | #endif |
---|