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 <Nicholas.Lowell@lexmark.com>
This commit is contained in:
Nicholas Lowell 2025-04-14 10:15:42 -04:00 committed by Benjamin Cabé
commit e60070d91b
2 changed files with 7 additions and 9 deletions

View file

@ -11,11 +11,6 @@
#ifdef CONFIG_POSIX_API #ifdef CONFIG_POSIX_API
#include <zephyr/fs/fs.h> #include <zephyr/fs/fs.h>
#endif #endif
#ifdef CONFIG_NETWORKING
/* For zsock_gethostname() */
#include <zephyr/net/socket.h>
#include <zephyr/net/hostname.h>
#endif
#include <zephyr/posix/sys/confstr.h> #include <zephyr/posix/sys/confstr.h>
#include <zephyr/posix/sys/stat.h> #include <zephyr/posix/sys/stat.h>
#include <zephyr/posix/sys/sysconf.h> #include <zephyr/posix/sys/sysconf.h>
@ -49,10 +44,7 @@ int rmdir(const char *path);
FUNC_NORETURN void _exit(int status); FUNC_NORETURN void _exit(int status);
#ifdef CONFIG_NETWORKING #ifdef CONFIG_NETWORKING
static inline int gethostname(char *buf, size_t len) int gethostname(char *buf, size_t len);
{
return zsock_gethostname(buf, len);
}
#endif /* CONFIG_NETWORKING */ #endif /* CONFIG_NETWORKING */
#endif /* CONFIG_POSIX_API */ #endif /* CONFIG_POSIX_API */

View file

@ -10,6 +10,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <zephyr/net/net_if.h> #include <zephyr/net/net_if.h>
#include <zephyr/net/socket.h>
#include <zephyr/posix/arpa/inet.h> #include <zephyr/posix/arpa/inet.h>
#include <zephyr/posix/netinet/in.h> #include <zephyr/posix/netinet/in.h>
#include <zephyr/posix/net/if.h> #include <zephyr/posix/net/if.h>
@ -216,6 +217,11 @@ struct hostent *gethostent(void)
return NULL; return NULL;
} }
int gethostname(char *buf, size_t len)
{
return zsock_gethostname(buf, len);
}
int getnameinfo(const struct sockaddr *addr, socklen_t addrlen, char *host, socklen_t hostlen, int getnameinfo(const struct sockaddr *addr, socklen_t addrlen, char *host, socklen_t hostlen,
char *serv, socklen_t servlen, int flags) char *serv, socklen_t servlen, int flags)
{ {