Skip to content

Commit ef9af4f

Browse files
committed
lib: libc: minimal: Define off_t as intptr_t
The `off_t` type, which is specified by the POSIX standard as a signed integer type representing file sizes, was defined as `long` or `int` depending on the target architecture without a clear explanation on why it was defined as such. While the POSIX standard does not specify the size requirement of the `off_t` type, it generally corresponds to the size of a pointer in practice, mainly because the optimal file handling size is closely tied to the native pointer size. For this reason, this commit removes the per-architecture `off_t` definition and defines it as `intptr_t` such that its size always matches the native pointer size. Note that the toolchain-defined `__INTPTR_TYPE__` macro is used instead of the `intptr_t` typedef as per the common convention used in the C standard library headers. Signed-off-by: Stephanos Ioannidis <[email protected]>
1 parent 9a7e4b1 commit ef9af4f

File tree

1 file changed

+2
-21
lines changed
  • lib/libc/minimal/include/sys

1 file changed

+2
-21
lines changed

lib/libc/minimal/include/sys/types.h

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,8 @@ typedef __SIZE_TYPE__ ssize_t;
3232

3333
#if !defined(__off_t_defined)
3434
#define __off_t_defined
35-
36-
#if defined(__i386) || defined(__x86_64) || defined(__ARC64__)
37-
typedef long int off_t; /* "long" works for all of i386, X32 and true 64 bit */
38-
#elif defined(__ARM_ARCH)
39-
typedef int off_t;
40-
#elif defined(__arc__)
41-
typedef int off_t;
42-
#elif defined(__NIOS2__)
43-
typedef int off_t;
44-
#elif defined(__riscv)
45-
typedef int off_t;
46-
#elif defined(__XTENSA__)
47-
typedef int off_t;
48-
#elif defined(__sparc__)
49-
typedef int off_t;
50-
#elif defined(__mips)
51-
typedef int off_t;
52-
#else
53-
#error "The minimal libc library does not recognize the architecture!\n"
54-
#endif
55-
35+
/* off_t is defined such that it matches the size of a pointer */
36+
typedef __INTPTR_TYPE__ off_t;
5637
#endif
5738

5839
#if !defined(__time_t_defined)

0 commit comments

Comments
 (0)