source: rtems/c/src/lib/libc/lseek.c @ 4de102cc

4.104.114.84.95
Last change on this file since 4de102cc was a02224e, checked in by Joel Sherrill <joel.sherrill@…>, on 01/04/02 at 18:29:37

2002-01-04 Ralf Corsepius <corsepiu@…>

  • include/rtems/libio_.h: Remove set_errno_and_return_minus_one.
  • libc/cfsetispeed.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/cfsetospeed.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/chdir.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/chmod.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/chown.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/chroot.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/closedir.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/eval.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/fchdir.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/fchmod.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/fdatasync.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/fpathconf.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/fstat.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/fsync.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/ftruncate.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/getdents.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/ioctl.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/link.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/lseek.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/mknod.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/open.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/read.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/readlink.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/rmdir.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/stat.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/symlink.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/tcsetattr.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/telldir.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/ttyname.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/ttyname_r.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/unlink.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/unmount.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/utime.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/write.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • Property mode set to 100644
File size: 1.8 KB
Line 
1/*
2 *  lseek() - POSIX 1003.1b 6.5.3 - Reposition Read/Write File Offset
3 *
4 *  COPYRIGHT (c) 1989-1999.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.OARcorp.com/rtems/license.html.
10 *
11 *  $Id$
12 */
13
14#if HAVE_CONFIG_H
15#include "config.h"
16#endif
17
18#include <stdio.h>
19
20#include <rtems/libio_.h>
21#include <rtems/seterr.h>
22
23off_t lseek(
24  int     fd,
25  off_t   offset,
26  int     whence
27)
28{
29  rtems_libio_t *iop;
30  off_t          old_offset;
31  off_t          status;
32
33  rtems_libio_check_fd( fd );
34  iop = rtems_libio_iop( fd );
35  rtems_libio_check_is_open(iop);
36
37  /*
38   *  Check as many errors as possible before touching iop->offset.
39   */
40
41  if ( !iop->handlers->lseek_h )
42    rtems_set_errno_and_return_minus_one( ENOTSUP );
43
44  /*
45   *  Now process the lseek().
46   */
47
48  old_offset = iop->offset;
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      rtems_set_errno_and_return_minus_one( EINVAL );
64  }
65
66  /*
67   *  At this time, handlers assume iop->offset has the desired
68   *  new offset.
69   */
70
71  status = (*iop->handlers->lseek_h)( iop, offset, whence );
72  if ( status == (off_t) -1 )
73    iop->offset = old_offset;
74
75  /*
76   *  So if the operation failed, we have to restore iop->offset.
77   */
78
79  return status;
80}
81
82/*
83 *  _lseek_r
84 *
85 *  This is the Newlib dependent reentrant version of lseek().
86 */
87
88#if defined(RTEMS_NEWLIB)
89
90#include <reent.h>
91
92off_t _lseek_r(
93  struct _reent *ptr,
94  int            fd,
95  off_t          offset,
96  int            whence
97)
98{
99  return lseek( fd, offset, whence );
100}
101#endif
102
Note: See TracBrowser for help on using the repository browser.