[ac7d5ef0] | 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 | * |
---|
[60b791ad] | 9 | * COPYRIGHT (c) 1989-1998. |
---|
[ac7d5ef0] | 10 | * On-Line Applications Research Corporation (OAR). |
---|
[03f2154e] | 11 | * Copyright assigned to U.S. Government, 1994. |
---|
[ac7d5ef0] | 12 | * |
---|
[98e4ebf5] | 13 | * The license and distribution terms for this file may be |
---|
| 14 | * found in the file LICENSE in this distribution or at |
---|
[03f2154e] | 15 | * http://www.OARcorp.com/rtems/license.html. |
---|
[ac7d5ef0] | 16 | * |
---|
| 17 | * $Id$ |
---|
| 18 | * |
---|
| 19 | */ |
---|
| 20 | |
---|
| 21 | #include <sys/types.h> |
---|
| 22 | #include <sys/stat.h> |
---|
[331d9e3b] | 23 | #include <assert.h> |
---|
[dcec5a4] | 24 | #include <errno.h> |
---|
| 25 | #include <string.h> |
---|
| 26 | #include <stdio.h> /* only for puts */ |
---|
[ac7d5ef0] | 27 | |
---|
[41c58154] | 28 | #include <rtems.h> |
---|
[4dc0fd6] | 29 | #include <rtems/libio.h> |
---|
[41c58154] | 30 | |
---|
| 31 | #ifdef RTEMS_NEWLIB |
---|
[217e398] | 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 | |
---|
[dcec5a4] | 37 | int __rtems_fstat(int _fd, struct stat* _sbuf) |
---|
[ac7d5ef0] | 38 | { |
---|
[217e398] | 39 | #ifdef HAVE_BLKSIZE |
---|
| 40 | _sbuf->st_blksize = 0; |
---|
| 41 | #endif |
---|
[4dc0fd6] | 42 | |
---|
| 43 | /* |
---|
| 44 | * For now assume stdin/stdout/stderr are always a TTY line |
---|
[866c465f] | 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..... |
---|
[4dc0fd6] | 51 | */ |
---|
| 52 | if (_fd <= 2) { |
---|
| 53 | _sbuf->st_mode = S_IFCHR; |
---|
| 54 | } else { |
---|
| 55 | switch (rtems_file_descriptor_type (_fd)) { |
---|
[9646d5be] | 56 | case RTEMS_FILE_DESCRIPTOR_TYPE_FILE: |
---|
| 57 | _sbuf->st_mode = S_IFREG; |
---|
| 58 | break; |
---|
| 59 | |
---|
[4dc0fd6] | 60 | case RTEMS_FILE_DESCRIPTOR_TYPE_SOCKET: |
---|
| 61 | _sbuf->st_mode = S_IFSOCK; |
---|
| 62 | break; |
---|
| 63 | |
---|
| 64 | default: |
---|
[9646d5be] | 65 | puts( "__rtems_fstat -- unknown file descriptor type" ); |
---|
[4dc0fd6] | 66 | assert( 0 ); |
---|
| 67 | } |
---|
| 68 | } |
---|
[217e398] | 69 | return 0; |
---|
[ac7d5ef0] | 70 | } |
---|
| 71 | |
---|
[dcec5a4] | 72 | int __rtems_isatty(int _fd) |
---|
[ac7d5ef0] | 73 | { |
---|
[4dc0fd6] | 74 | struct stat st; |
---|
| 75 | |
---|
| 76 | if (__rtems_fstat(_fd, &st) < 0) |
---|
| 77 | return 0; |
---|
| 78 | return S_ISCHR (st.st_mode); |
---|
[ac7d5ef0] | 79 | } |
---|
| 80 | |
---|
[41c58154] | 81 | #if !defined(RTEMS_UNIX) |
---|
[ac7d5ef0] | 82 | int stat( const char *path, struct stat *buf ) |
---|
| 83 | { |
---|
[331d9e3b] | 84 | if ( strncmp( "/dev/", path, 5 ) ) { |
---|
[c6126e57] | 85 | return -1; |
---|
[331d9e3b] | 86 | } |
---|
[dcec5a4] | 87 | return __rtems_fstat( 0, buf ); |
---|
[ac7d5ef0] | 88 | } |
---|
| 89 | |
---|
| 90 | int link( const char *existing, const char *new ) |
---|
| 91 | { |
---|
| 92 | /* always fail */ |
---|
| 93 | return -1; |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | int unlink( const char *path ) |
---|
| 97 | { |
---|
| 98 | /* always fail */ |
---|
| 99 | return -1; |
---|
| 100 | } |
---|
| 101 | |
---|
[334b01f1] | 102 | char *getcwd( char *_buf, size_t _size) |
---|
| 103 | { |
---|
| 104 | |
---|
[dcec5a4] | 105 | /* assert( FALSE ); */ |
---|
| 106 | errno = ENOSYS; |
---|
| 107 | return 0; |
---|
| 108 | } |
---|
| 109 | int fork() { |
---|
| 110 | puts( "fork -- not supported!!!" ); |
---|
| 111 | assert( 0 ); |
---|
| 112 | errno = ENOSYS; |
---|
| 113 | return -1; |
---|
| 114 | } |
---|
| 115 | int execv(const char *_path, char * const _argv[] ) { |
---|
| 116 | puts( "execv -- not supported!!!" ); |
---|
| 117 | assert( 0 ); |
---|
| 118 | errno = ENOSYS; |
---|
| 119 | return -1; |
---|
| 120 | } |
---|
| 121 | int wait() { |
---|
| 122 | puts( "wait -- not supported!!!" ); |
---|
| 123 | assert( 0 ); |
---|
| 124 | errno = ENOSYS; |
---|
| 125 | return -1; |
---|
| 126 | } |
---|
[41c58154] | 127 | #endif |
---|
[dcec5a4] | 128 | |
---|
[ac7d5ef0] | 129 | #endif |
---|