source: rtems/cpukit/libcsupport/src/lseek.c @ 07a3253d

4.104.114.84.95
Last change on this file since 07a3253d 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: 1.7 KB
Line 
1/*
2 *  lseek() - POSIX 1003.1b 6.5.3 - Reposition Read/Write File Offset
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 <stdio.h>
16
17#include "libio_.h"
18
19off_t lseek(
20  int     fd,
21  off_t   offset,
22  int     whence
23)
24{
25  rtems_libio_t *iop;
26
27  /*
28   *  If this file descriptor is mapped to an external set of handlers,
29   *  then pass the request on to them.
30   */
31
32  if ( rtems_file_descriptor_type( fd ) ) {
33    rtems_libio_lseek_t fp;
34
35    fp = rtems_libio_handlers[rtems_file_descriptor_type_index(fd)].lseek;
36    if ( fp == NULL )
37      set_errno_and_return_minus_one( EBADF );
38
39    return (*fp)( fd, offset, whence );
40  }
41
42  /*
43   *  Now process the lseek().
44   */
45
46  iop = rtems_libio_iop( fd );
47  rtems_libio_check_fd( fd );
48
49  switch ( whence ) {
50    case SEEK_SET:
51      iop->offset = offset;
52      break;
53
54    case SEEK_CUR:
55      iop->offset += offset;
56      break;
57
58    case SEEK_END:
59      iop->offset = iop->size - offset;
60      break;
61
62    default:
63      errno = EINVAL;
64      return -1;
65  }
66
67  if ( !iop->handlers->lseek )
68    set_errno_and_return_minus_one( ENOTSUP );
69
70  return (*iop->handlers->lseek)( iop, offset, whence );
71}
72
73/*
74 *  _lseek_r
75 *
76 *  This is the Newlib dependent reentrant version of lseek().
77 */
78
79#if defined(RTEMS_NEWLIB)
80
81#include <reent.h>
82
83off_t _lseek_r(
84  struct _reent *ptr,
85  int            fd,
86  off_t          offset,
87  int            whence
88)
89{
90  return lseek( fd, offset, whence );
91}
92#endif
93
Note: See TracBrowser for help on using the repository browser.