source: rtems/c/src/lib/libc/syscalls.c @ 9646d5be

4.104.114.84.95
Last change on this file since 9646d5be was 9646d5be, checked in by Joel Sherrill <joel.sherrill@…>, on Feb 17, 1998 at 6:46:38 PM

Patch from Eric Norum <eric@…>:

I've gone through and cleaned up the TFTP driver so that it fits
into the libio system. Here's the comment from the new driver:

/*

  • Usage: *
  • To open /bootfiles/image' on hostname' for reading:
  • fd = open ("/TFTP/hostname/bootfiles/image", O_RDONLY); *
  • The `hostname' can be a symbolic name or four
  • dot-separated decimal values. *
  • To open a file on the host which supplied the BOOTP
  • information just leave the `hostname' part empty:
  • fd = open ("/TFTPbootfiles/image", O_RDONLY); * */

You can `fopen' TFTP files the same way:

fp = fopen (fullname, "r");
nread = fread (cbuf, sizeof cbuf[0], sizeof cbuf, fp);

The diff's are included below. I've also modified the TFTP demo
program and the bootstrap PROM example. They should be on my ftp
site `soon'.

The one thing I don't like is the way I had to do an end-run on the
libio routines to get errno passed back from my driver to the
application (since there are some errno codes that don't map to RTEMS
status codes). My approach was to set errno in the driver and have
the driver routine return an RTEMS status code that I `know' isn't in
the errno_assoc[] in libio.c.

Perhaps there should be an RTEMS_TRANPARENT_ERRNO status code (or
something similar) which driver routines could return to indicate
that the driver routine has set errno and that the libio routines
shouldn't attempt to map the returned status code to errno.

Actually, I think the entire I/O system needs looking at -- as
you've already mentioned. The hacks I've dropped in to syscalls.c to
make fstat work, for example, are *not* shining examples of good
code......

  • Property mode set to 100644
File size: 2.6 KB
Line 
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
37int __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_FILE:
57      _sbuf->st_mode = S_IFREG;
58      break;
59
60    case RTEMS_FILE_DESCRIPTOR_TYPE_SOCKET:
61      _sbuf->st_mode = S_IFSOCK;
62      break;
63
64    default:
65      puts( "__rtems_fstat -- unknown file descriptor type" );
66      assert( 0 );
67    }
68  }
69  return 0;
70}
71
72int __rtems_isatty(int _fd)
73{
74  struct stat st;
75
76  if (__rtems_fstat(_fd, &st) < 0)
77    return 0;
78  return S_ISCHR (st.st_mode);
79}
80
81#if !defined(RTEMS_UNIX)
82int stat( const char *path, struct stat *buf )
83{
84  if ( strncmp( "/dev/", path, 5 ) ) {
85    return -1;
86  }
87  return __rtems_fstat( 0, buf );
88}
89
90int link( const char *existing, const char *new )
91{
92  /* always fail */
93  return -1;
94}
95
96int unlink( const char *path )
97{
98  /* always fail */
99  return -1;
100}
101
102char *getcwd( char *_buf, size_t _size)
103{
104
105/*  assert( FALSE ); */
106  errno = ENOSYS;
107  return 0;
108}
109int fork() {
110  puts( "fork -- not supported!!!" );
111  assert( 0 );
112  errno = ENOSYS;
113  return -1;
114}
115int execv(const char *_path, char * const _argv[] ) {
116  puts( "execv -- not supported!!!" ); 
117  assert( 0 );
118  errno = ENOSYS;
119  return -1;
120}
121int wait() {
122  puts( "wait -- not supported!!!" );
123  assert( 0 );
124  errno = ENOSYS;
125  return -1;
126}
127#endif
128
129#endif
Note: See TracBrowser for help on using the repository browser.