From eba2aaa5703dfea5393ed8fb02d231856cba61fd Mon Sep 17 00:00:00 2001 From: Andre Maroneze <andre.maroneze@cea.fr> Date: Tue, 4 May 2021 17:11:43 +0200 Subject: [PATCH] [libc] minor fixes and improvements --- share/libc/netdb.h | 8 ++++++++ share/libc/unistd.h | 7 ++++++- tests/libc/netdb_c.c | 8 -------- tests/libc/unistd_h.c | 3 +++ 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/share/libc/netdb.h b/share/libc/netdb.h index d3efadce2b5..e58a1ca1f63 100644 --- a/share/libc/netdb.h +++ b/share/libc/netdb.h @@ -99,6 +99,14 @@ struct addrinfo # define NI_DGRAM 16 /* Look up UDP service rather than TCP. */ # define NI_NUMERICSCOPE 32 +// Non-POSIX +#ifndef NI_MAXHOST +# define NI_MAXHOST 1025 +#endif +#ifndef NI_MAXSERV +# define NI_MAXSERV 32 +#endif + # define EAI_BADFLAGS -1 /* Invalid value for `ai_flags' field. */ # define EAI_NONAME -2 /* NAME or SERVICE is unknown. */ # define EAI_AGAIN -3 /* Temporary failure in name resolution. */ diff --git a/share/libc/unistd.h b/share/libc/unistd.h index c0c279864ed..f7cead96aae 100644 --- a/share/libc/unistd.h +++ b/share/libc/unistd.h @@ -1079,7 +1079,12 @@ extern pid_t setsid(void); */ extern int setuid(uid_t uid); -extern unsigned int sleep(unsigned int); +/*@ + assigns \result \from seconds; + ensures unslept: 0 <= \result <= seconds; + */ +extern unsigned int sleep(unsigned int seconds); + extern void swab(const void *, void *, ssize_t); extern int symlink(const char *, const char *); diff --git a/tests/libc/netdb_c.c b/tests/libc/netdb_c.c index c2f9a8c9d34..343f21234e0 100644 --- a/tests/libc/netdb_c.c +++ b/tests/libc/netdb_c.c @@ -12,14 +12,6 @@ #define BUF_SIZE 500 -// Non-POSIX -#ifndef NI_MAXHOST -# define NI_MAXHOST 1025 -#endif -#ifndef NI_MAXSERV -# define NI_MAXSERV 32 -#endif - int main() { struct addrinfo hints; struct addrinfo *result, *rp; diff --git a/tests/libc/unistd_h.c b/tests/libc/unistd_h.c index 8f0f40681fd..5bb417437e2 100644 --- a/tests/libc/unistd_h.c +++ b/tests/libc/unistd_h.c @@ -104,5 +104,8 @@ int main() { r = pipe(pipefd); //@ check ok: r == 0 || r == -1; + int unslept = sleep(42); + //@ assert 0 <= unslept <= 42; + return 0; } -- GitLab