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-1998. |
---|
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 | int __rtems_fstat(int _fd, struct stat* _sbuf) |
---|
34 | { |
---|
35 | #ifdef HAVE_BLKSIZE |
---|
36 | _sbuf->st_blksize = 0; |
---|
37 | #endif |
---|
38 | |
---|
39 | /* |
---|
40 | * For now assume stdin/stdout/stderr are always a TTY line |
---|
41 | * |
---|
42 | * From Eric Norum: |
---|
43 | * |
---|
44 | * The `fix' is not complete. It still doesn't properly handle |
---|
45 | * file descriptors for any files/devices other than the console |
---|
46 | * serial lines..... |
---|
47 | */ |
---|
48 | if (_fd <= 2) { |
---|
49 | _sbuf->st_mode = S_IFCHR; |
---|
50 | } else { |
---|
51 | switch (rtems_file_descriptor_type (_fd)) { |
---|
52 | case RTEMS_FILE_DESCRIPTOR_TYPE_FILE: |
---|
53 | _sbuf->st_mode = S_IFREG; |
---|
54 | break; |
---|
55 | |
---|
56 | case RTEMS_FILE_DESCRIPTOR_TYPE_SOCKET: |
---|
57 | #if !defined(__GO32__) |
---|
58 | _sbuf->st_mode = S_IFSOCK; |
---|
59 | break; |
---|
60 | #endif |
---|
61 | |
---|
62 | default: |
---|
63 | puts( "__rtems_fstat -- unknown file descriptor type" ); |
---|
64 | assert( 0 ); |
---|
65 | } |
---|
66 | } |
---|
67 | return 0; |
---|
68 | } |
---|
69 | |
---|
70 | #if !defined(RTEMS_UNIX) |
---|
71 | int stat( const char *path, struct stat *buf ) |
---|
72 | { |
---|
73 | if ( strncmp( "/dev/", path, 5 ) ) { |
---|
74 | return -1; |
---|
75 | } |
---|
76 | return __rtems_fstat( 0, buf ); |
---|
77 | } |
---|
78 | |
---|
79 | int link( const char *existing, const char *new ) |
---|
80 | { |
---|
81 | /* always fail */ |
---|
82 | return -1; |
---|
83 | } |
---|
84 | |
---|
85 | int unlink( const char *path ) |
---|
86 | { |
---|
87 | /* always fail */ |
---|
88 | return -1; |
---|
89 | } |
---|
90 | |
---|
91 | char *getcwd( char *_buf, size_t _size) |
---|
92 | { |
---|
93 | /* assert( FALSE ); */ |
---|
94 | errno = ENOSYS; |
---|
95 | return 0; |
---|
96 | } |
---|
97 | |
---|
98 | int fork() { |
---|
99 | puts( "fork -- not supported!!!" ); |
---|
100 | assert( 0 ); |
---|
101 | errno = ENOSYS; |
---|
102 | return -1; |
---|
103 | } |
---|
104 | #if 0 |
---|
105 | int execv(const char *_path, char * const _argv[] ) { |
---|
106 | puts( "execv -- not supported!!!" ); |
---|
107 | assert( 0 ); |
---|
108 | errno = ENOSYS; |
---|
109 | return -1; |
---|
110 | } |
---|
111 | #endif |
---|
112 | int wait() { |
---|
113 | puts( "wait -- not supported!!!" ); |
---|
114 | assert( 0 ); |
---|
115 | errno = ENOSYS; |
---|
116 | return -1; |
---|
117 | } |
---|
118 | #endif |
---|
119 | |
---|
120 | #endif |
---|