Skip to content

Commit 6d126e7

Browse files
tbr-ttandrewboie
authored andcommitted
lib/posix: SPARC newlib has unsigned short mode_t
This commit eliminates a compilation error by passing int to va_arg rather than mode_t on SPARC. Newlib sys/_types.h defines mode_t for SPARC as: typedef unsigned short __mode_t; GCC 10.2.0 gave the following error message and suggested solution: mqueue.c: In function 'mq_open': mqueue.c:61:21: error: 'mode_t' {aka 'short unsigned int'} is promoted to 'int' when passed through '...' [-Werror] 61 | mode = va_arg(va, mode_t); | ^ mqueue.c:61:21: note: (so you should pass 'int' not 'mode_t' {aka 'short unsigned int'} to 'va_arg') Signed-off-by: Martin Åberg <[email protected]>
1 parent 2b1baf6 commit 6d126e7

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

lib/posix/mqueue.c

+12-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@ static int receive_message(mqueue_desc *mqd, char *msg_ptr, size_t msg_len,
3838
k_timeout_t timeout);
3939
static void remove_mq(mqueue_object *msg_queue);
4040

41+
#if defined(__sparc__)
42+
/*
43+
* mode_t is defined as "unsigned short" on SPARC newlib. This type is promoted
44+
* to "int" when passed through '...' so we should pass the promoted type to
45+
* va_arg().
46+
*/
47+
#define PROMOTED_MODE_T int
48+
#else
49+
#define PROMOTED_MODE_T mode_t
50+
#endif
51+
4152
/**
4253
* @brief Open a message queue.
4354
*
@@ -58,7 +69,7 @@ mqd_t mq_open(const char *name, int oflags, ...)
5869

5970
va_start(va, oflags);
6071
if ((oflags & O_CREAT) != 0) {
61-
mode = va_arg(va, mode_t);
72+
mode = va_arg(va, PROMOTED_MODE_T);
6273
attrs = va_arg(va, mq_attr*);
6374
}
6475
va_end(va);

0 commit comments

Comments
 (0)