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

5
Last change on this file since cfe8f7a was cfe8f7a, checked in by Sebastian Huber <sebastian.huber@…>, on 04/27/20 at 14:14:06

doxygen: Switch @brief and @ingroup

This order change fixes the Latex documentation build via Doxygen.

  • Property mode set to 100644
File size: 1.5 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup LibIOFSOps File System Operations
5 *
6 * @brief RTEMS Default File System reposits the offset of the open file fd
7 */
8
9/*
10 * Copyright (c) 2012 embedded brains GmbH.  All rights reserved.
11 *
12 *  embedded brains GmbH
13 *  Obere Lagerstr. 30
14 *  82178 Puchheim
15 *  Germany
16 *  <rtems@embedded-brains.de>
17 *
18 * The license and distribution terms for this file may be
19 * found in the file LICENSE in this distribution or at
20 * http://www.rtems.org/license/LICENSE.
21 */
22
23#ifdef HAVE_CONFIG_H
24#include "config.h"
25#endif
26
27#include <rtems/libio_.h>
28
29off_t rtems_filesystem_default_lseek_file(
30  rtems_libio_t *iop,
31  off_t offset,
32  int whence
33)
34{
35  off_t rv = 0;
36  off_t reference_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
57  if ( rv == 0 ) {
58    off_t new_offset = reference_offset + offset;
59
60    if (
61      (offset >= 0 && new_offset >= reference_offset)
62        || (offset < 0 && new_offset < reference_offset)
63    ) {
64      if ( new_offset >= 0 ) {
65        iop->offset = new_offset;
66        rv = new_offset;
67      } else {
68        errno = EINVAL;
69        rv = -1;
70      }
71    } else {
72      errno = EOVERFLOW;
73      rv = -1;
74    }
75  }
76
77  return rv;
78}
Note: See TracBrowser for help on using the repository browser.