Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:30

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  * Copyright (c) 2012 embedded brains GmbH & Co. KG
0005  *
0006  * Redistribution and use in source and binary forms, with or without
0007  * modification, are permitted provided that the following conditions
0008  * are met:
0009  * 1. Redistributions of source code must retain the above copyright
0010  *    notice, this list of conditions and the following disclaimer.
0011  * 2. Redistributions in binary form must reproduce the above copyright
0012  *    notice, this list of conditions and the following disclaimer in the
0013  *    documentation and/or other materials provided with the distribution.
0014  *
0015  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0016  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0017  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0018  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0019  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0020  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0021  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0022  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0023  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0024  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0025  * POSSIBILITY OF SUCH DAMAGE.
0026  */
0027 
0028 #ifdef HAVE_CONFIG_H
0029 #include "config.h"
0030 #endif
0031 
0032 #include "tmacros.h"
0033 
0034 #include <sys/types.h>
0035 #include <stdio.h>
0036 #include <errno.h>
0037 #include <inttypes.h>
0038 #include <limits.h>
0039 
0040 const char rtems_test_name[] = "FSFSEEKO 1";
0041 
0042 static void test(void)
0043 {
0044   FILE *file;
0045   int rv;
0046   const off_t off = sizeof(off_t) >= sizeof(int64_t)
0047     ? INT64_MAX
0048     : (sizeof(off_t) == sizeof(int32_t) ? INT32_MAX : 1);
0049   off_t actual_off;
0050   const long long_off = LONG_MAX;
0051   long actual_long_off;
0052 
0053   errno = 0;
0054   file = fopen("file", "w+");
0055   rtems_test_assert(file != NULL);
0056   rtems_test_assert(errno == 0);
0057 
0058   errno = 0;
0059   rv = fseek(file, long_off, SEEK_SET);
0060   rtems_test_assert(rv == 0);
0061   rtems_test_assert(errno == 0);
0062 
0063   errno = 0;
0064   actual_long_off = ftell(file);
0065   rtems_test_assert(actual_long_off == long_off);
0066   rtems_test_assert(errno == 0);
0067 
0068   errno = 0;
0069   actual_off = ftello(file);
0070   rtems_test_assert(actual_off == long_off);
0071   rtems_test_assert(errno == 0);
0072 
0073   errno = 0;
0074   rv = fseeko(file, off, SEEK_SET);
0075   rtems_test_assert(rv == 0);
0076   rtems_test_assert(errno == 0);
0077 
0078   if (sizeof(off_t) == sizeof(long)) {
0079     errno = 0;
0080     actual_long_off = ftell(file);
0081     rtems_test_assert(actual_long_off == off);
0082     rtems_test_assert(errno == 0);
0083   } else {
0084     errno = 0;
0085     actual_long_off = ftell(file);
0086     rtems_test_assert(actual_long_off == -1L);
0087     rtems_test_assert(errno == EOVERFLOW);
0088   }
0089 
0090   errno = 0;
0091   actual_off = ftello(file);
0092   rtems_test_assert(actual_off == off);
0093   rtems_test_assert(errno == 0);
0094 
0095   errno = 0;
0096   rv = fclose(file);
0097   rtems_test_assert(rv == 0);
0098   rtems_test_assert(errno == 0);
0099 }
0100 
0101 static void Init(rtems_task_argument arg)
0102 {
0103   TEST_BEGIN();
0104 
0105   test();
0106 
0107   TEST_END();
0108   rtems_test_exit(0);
0109 }
0110 
0111 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
0112 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0113 
0114 #define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS 4
0115 
0116 #define CONFIGURE_MAXIMUM_TASKS 1
0117 
0118 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0119 
0120 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0121 
0122 #define CONFIGURE_INIT
0123 
0124 #include <rtems/confdefs.h>