Skip to content

Commit 613efa4

Browse files
Nicholas LowellNicholas Lowell
Nicholas Lowell
authored and
Nicholas Lowell
committed
posix: net: move static inline gethostname() to lib definition
static inline gethostname() in unistd.h can cause declaration collisions. we should just move it to a normal function definition like the rest of the network functions. Signed-off-by: Nicholas Lowell <[email protected]>
1 parent f39668d commit 613efa4

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

include/zephyr/posix/unistd.h

+1-9
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@
1111
#ifdef CONFIG_POSIX_API
1212
#include <zephyr/fs/fs.h>
1313
#endif
14-
#ifdef CONFIG_NETWORKING
15-
/* For zsock_gethostname() */
16-
#include <zephyr/net/socket.h>
17-
#include <zephyr/net/hostname.h>
18-
#endif
1914
#include <zephyr/posix/sys/confstr.h>
2015
#include <zephyr/posix/sys/stat.h>
2116
#include <zephyr/posix/sys/sysconf.h>
@@ -49,10 +44,7 @@ int rmdir(const char *path);
4944
FUNC_NORETURN void _exit(int status);
5045

5146
#ifdef CONFIG_NETWORKING
52-
static inline int gethostname(char *buf, size_t len)
53-
{
54-
return zsock_gethostname(buf, len);
55-
}
47+
int gethostname(char *buf, size_t len);
5648
#endif /* CONFIG_NETWORKING */
5749

5850
#endif /* CONFIG_POSIX_API */

lib/posix/options/net.c

+6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <stdlib.h>
1111

1212
#include <zephyr/net/net_if.h>
13+
#include <zephyr/net/socket.h>
1314
#include <zephyr/posix/arpa/inet.h>
1415
#include <zephyr/posix/netinet/in.h>
1516
#include <zephyr/posix/net/if.h>
@@ -216,6 +217,11 @@ struct hostent *gethostent(void)
216217
return NULL;
217218
}
218219

220+
int gethostname(char *buf, size_t len)
221+
{
222+
return zsock_gethostname(buf, len);
223+
}
224+
219225
int getnameinfo(const struct sockaddr *addr, socklen_t addrlen, char *host, socklen_t hostlen,
220226
char *serv, socklen_t servlen, int flags)
221227
{

0 commit comments

Comments
 (0)