source: rtems/cpukit/libfs/src/defaults/default_lseek_file.c @ b8fc260f

4.115
Last change on this file since b8fc260f was 8587b01, checked in by Ayush Awasthi <kolaveridi87@…>, on 12/28/12 at 14:26:30

libfs: Doxygen Enhancement Task #4

  • Property mode set to 100644
File size: 1.5 KB
Line 
1/**
2 * @file
3 *
4 * @brief RTEMS Default File System reposits the offset of the open file fd
5 * @ingroup LibIOFSOps File System Operations
6 */
7
8/*
9 * Copyright (c) 2012 embedded brains GmbH.  All rights reserved.
10 *
11 *  embedded brains GmbH
12 *  Obere Lagerstr. 30
13 *  82178 Puchheim
14 *  Germany
15 *  <rtems@embedded-brains.de>
16 *
17 * The license and distribution terms for this file may be
18 * found in the file LICENSE in this distribution or at
19 * http://www.rtems.com/license/LICENSE.
20 */
21
22#if HAVE_CONFIG_H
23  #include "config.h"
24#endif
25
26#include <rtems/libio_.h>
27
28off_t rtems_filesystem_default_lseek_file(
29  rtems_libio_t *iop,
30  off_t offset,
31  int whence
32)
33{
34  off_t rv = 0;
35  off_t reference_offset;
36  off_t new_offset;
37  struct stat st;
38
39  switch ( whence ) {
40    case SEEK_SET:
41      reference_offset = 0;
42      break;
43    case SEEK_CUR:
44      reference_offset = iop->offset;
45      break;
46    case SEEK_END:
47      st.st_size = 0;
48      rv = (*iop->pathinfo.handlers->fstat_h)( &iop->pathinfo, &st );
49      reference_offset = st.st_size;
50      break;
51    default:
52      errno = EINVAL;
53      rv = -1;
54      break;
55  }
56  new_offset = reference_offset + offset;
57
58  if ( rv == 0 ) {
59    if (
60      (offset >= 0 && new_offset >= reference_offset)
61        || (offset < 0 && new_offset < reference_offset)
62    ) {
63      if ( new_offset >= 0 ) {
64        iop->offset = new_offset;
65        rv = new_offset;
66      } else {
67        errno = EINVAL;
68        rv = -1;
69      }
70    } else {
71      errno = EOVERFLOW;
72      rv = -1;
73    }
74  }
75
76  return rv;
77}
Note: See TracBrowser for help on using the repository browser.