source: rtems/testsuites/fstests/fsfseeko01/init.c @ f820f22c

4.11
Last change on this file since f820f22c was f820f22c, checked in by Sebastian Huber <sebastian.huber@…>, on Apr 8, 2015 at 5:46:10 AM

fstests/fsfseeko01: Fix for long == off_t

Close #2317.

  • Property mode set to 100644
File size: 2.4 KB
Line 
1/*
2 * Copyright (c) 2012 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Obere Lagerstr. 30
6 *  82178 Puchheim
7 *  Germany
8 *  <rtems@embedded-brains.de>
9 *
10 * The license and distribution terms for this file may be
11 * found in the file LICENSE in this distribution or at
12 * http://www.rtems.org/license/LICENSE.
13 */
14
15#ifdef HAVE_CONFIG_H
16  #include "config.h"
17#endif
18
19#include "tmacros.h"
20
21#include <sys/types.h>
22#include <stdio.h>
23#include <errno.h>
24#include <inttypes.h>
25#include <limits.h>
26
27const char rtems_test_name[] = "FSFSEEKO 1";
28
29static void test(void)
30{
31  FILE *file;
32  int rv;
33  const off_t off = sizeof(off_t) >= sizeof(int64_t)
34    ? INT64_MAX
35    : (sizeof(off_t) == sizeof(int32_t) ? INT32_MAX : 1);
36  off_t actual_off;
37  const long long_off = LONG_MAX;
38  long actual_long_off;
39
40  errno = 0;
41  file = fopen("file", "w+");
42  rtems_test_assert(file != NULL);
43  rtems_test_assert(errno == 0);
44
45  errno = 0;
46  rv = fseek(file, long_off, SEEK_SET);
47  rtems_test_assert(rv == 0);
48  rtems_test_assert(errno == 0);
49
50  errno = 0;
51  actual_long_off = ftell(file);
52  rtems_test_assert(actual_long_off == long_off);
53  rtems_test_assert(errno == 0);
54
55  errno = 0;
56  actual_off = ftello(file);
57  rtems_test_assert(actual_off == long_off);
58  rtems_test_assert(errno == 0);
59
60  errno = 0;
61  rv = fseeko(file, off, SEEK_SET);
62  rtems_test_assert(rv == 0);
63  rtems_test_assert(errno == 0);
64
65  if (sizeof(off_t) == sizeof(long)) {
66    errno = 0;
67    actual_long_off = ftell(file);
68    rtems_test_assert(actual_long_off == off);
69    rtems_test_assert(errno == 0);
70  } else {
71    errno = 0;
72    actual_long_off = ftell(file);
73    rtems_test_assert(actual_long_off == -1L);
74    rtems_test_assert(errno == EOVERFLOW);
75  }
76
77  errno = 0;
78  actual_off = ftello(file);
79  rtems_test_assert(actual_off == off);
80  rtems_test_assert(errno == 0);
81
82  errno = 0;
83  rv = fclose(file);
84  rtems_test_assert(rv == 0);
85  rtems_test_assert(errno == 0);
86}
87
88static void Init(rtems_task_argument arg)
89{
90  TEST_BEGIN();
91
92  test();
93
94  TEST_END();
95  rtems_test_exit(0);
96}
97
98#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
99#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
100
101#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 4
102
103#define CONFIGURE_MAXIMUM_TASKS 1
104
105#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
106
107#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
108
109#define CONFIGURE_INIT
110
111#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.