Skip to content

Commit

Permalink
libc: minimal: define off_t as a signed, 64-bit integer
Browse files Browse the repository at this point in the history
The off_t type effectively limits the maximum file size that
can be measured with a POSIX system. Rather than limiting it
to the word-size of the architecture (usually equivalent to
the pointer size), strictly use a signed, 64-bit integer.

Signed-off-by: Chris Friedt <[email protected]>
  • Loading branch information
Chris Friedt committed Jul 8, 2024
1 parent 5379f36 commit 65db7bb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
4 changes: 4 additions & 0 deletions lib/libc/minimal/include/sys/_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@

#include <stdint.h>

#include <zephyr/types.h>

typedef k_off_t _OFF_T_;
typedef k_ssize_t _SSIZE_T_;
typedef int64_t _TIME_T_;
typedef int32_t _SUSECONDS_T_;

Expand Down
17 changes: 2 additions & 15 deletions lib/libc/minimal/include/sys/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,12 @@ typedef unsigned int mode_t;

#if !defined(__ssize_t_defined)
#define __ssize_t_defined

/* Static code analysis tool can raise a violation
* in the line below where name of macro 'unsigned' is the same
* as keyword. It is made on purpose, deliberated deviation.
*
* We trick compiler to make sure the type of ssize_t won't be unsigned long.
* As otherwise the type of ssize_t will be unsigned long
* which is not correct. More details view in commit b889120
*/
#define unsigned signed /* parasoft-suppress MISRAC2012-RULE_20_4-a MISRAC2012-RULE_20_4-b */
typedef __SIZE_TYPE__ ssize_t;
#undef unsigned

typedef _SSIZE_T_ ssize_t;
#endif

#if !defined(__off_t_defined)
#define __off_t_defined
/* off_t is defined such that it matches the size of a pointer */
typedef __INTPTR_TYPE__ off_t;
typedef _OFF_T_ off_t;
#endif

#if !defined(__time_t_defined)
Expand Down

0 comments on commit 65db7bb

Please sign in to comment.