source: rtems/c/src/exec/libcsupport/src/write.c @ 6c980128

4.104.114.84.95
Last change on this file since 6c980128 was 07a3253d, checked in by Joel Sherrill <joel.sherrill@…>, on 11/23/98 at 19:07:58

Added base version of file system infrastructure. This includes a major
overhaul of the RTEMS system call interface. This base file system is
the "In-Memory File System" aka IMFS.

The design and implementation was done by the following people:

+ Joel Sherrill (joel@…)
+ Jennifer Averett (jennifer@…)
+ Steve "Mr Mount" Salitasc (salitasc@…)
+ Kerwin Wade (wade@…)

PROBLEMS
========

+ It is VERY likely that merging this will break the UNIX port. This

can/will be fixed.

+ There is likely some reentrancy/mutual exclusion needed.

+ Eventually, there should be a "mini-IMFS" description table to

eliminate links, symlinks, etc to save memory. All you need to
have "classic RTEMS" functionality is technically directories
and device IO. All the rest could be left out to save memory.

  • Property mode set to 100644
File size: 2.0 KB
Line 
1/*
2 *  write() - POSIX 1003.1b 6.4.2 - Write to a File
3 *
4 *  COPYRIGHT (c) 1989-1998.
5 *  On-Line Applications Research Corporation (OAR).
6 *  Copyright assigned to U.S. Government, 1994.
7 *
8 *  The license and distribution terms for this file may be
9 *  found in the file LICENSE in this distribution or at
10 *  http://www.OARcorp.com/rtems/license.html.
11 *
12 *  $Id$
13 */
14
15#include "libio_.h"
16
17
18/*
19 * write
20 *
21 * This routine writes count bytes from from buffer pointed to by buffer
22 * to the file associated with the open file descriptor, fildes.
23 */
24
25/* XXX newlib has the prototype for this wrong.  It will be a bit painful */
26/* XXX to fix so we are choosing to delay fixing this. */
27
28int write(                        /* XXX this should return a ssize_t */
29  int         fd,
30  const void *buffer,
31  unsigned32  count               /* XXX this should be a size_t */
32)
33{
34  rtems_status_code  rc;
35  rtems_libio_t     *iop;
36
37  /*
38   *  If this file descriptor is mapped to an external set of handlers,
39   *  then pass the request on to them.
40   */
41
42  if ( rtems_file_descriptor_type( fd ) ) {
43    rtems_libio_write_t fp;
44
45    fp = rtems_libio_handlers[rtems_file_descriptor_type_index(fd)].write;
46    if ( fp == NULL )
47      set_errno_and_return_minus_one( EBADF );
48
49    return (*fp)( fd, buffer, count );
50  }
51
52  /*
53   *  Now process the write() request.
54   */
55
56  iop = rtems_libio_iop( fd );
57  rtems_libio_check_fd( fd );
58  rtems_libio_check_buffer( buffer );
59  rtems_libio_check_count( count );
60  rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE );
61
62  if ( !iop->handlers->write )
63    set_errno_and_return_minus_one( ENOTSUP );
64
65  rc = (*iop->handlers->write)( iop, buffer, count );
66
67  if ( rc > 0 )
68    iop->offset += rc;
69
70  return rc;
71}
72
73/*
74 *  _write_r
75 *
76 *  This is the Newlib dependent reentrant version of write().
77 */
78
79#if defined(RTEMS_NEWLIB)
80
81#include <reent.h>
82
83long _write_r(
84  struct _reent *ptr,
85  int            fd,
86  const void    *buf,
87  size_t         nbytes
88)
89{
90  return write( fd, buf, nbytes );
91}
92#endif
Note: See TracBrowser for help on using the repository browser.