@@ -38,6 +38,13 @@ __errno_location(void);
3838 return -1; \
3939 }
4040
41+ /* REVISIT: in many cases, EAI_SYSTEM may not be an ideal error code */
42+ #define GAI_HANDLE_ERROR (error ) \
43+ if (error != __WASI_ERRNO_SUCCESS) { \
44+ errno = error; \
45+ return EAI_SYSTEM; \
46+ }
47+
4148static void
4249ipv4_addr_to_wasi_ip4_addr (uint32_t addr_num , __wasi_addr_ip4_t * out )
4350{
@@ -518,7 +525,7 @@ getaddrinfo(const char *node, const char *service, const struct addrinfo *hints,
518525 struct aibuf * aibuf_res ;
519526
520527 error = addrinfo_hints_to_wasi_hints (hints , & wasi_hints );
521- HANDLE_ERROR (error )
528+ GAI_HANDLE_ERROR (error )
522529
523530 do {
524531 if (addr_info )
@@ -529,29 +536,29 @@ getaddrinfo(const char *node, const char *service, const struct addrinfo *hints,
529536 * sizeof (__wasi_addr_info_t ));
530537
531538 if (!addr_info ) {
532- HANDLE_ERROR ( __WASI_ERRNO_NOMEM )
539+ return EAI_MEMORY ;
533540 }
534541
535542 error = __wasi_sock_addr_resolve (node , service == NULL ? "" : service ,
536543 & wasi_hints , addr_info , addr_info_size ,
537544 & max_info_size );
538545 if (error != __WASI_ERRNO_SUCCESS ) {
539546 free (addr_info );
540- HANDLE_ERROR (error );
547+ GAI_HANDLE_ERROR (error );
541548 }
542549 } while (max_info_size > addr_info_size );
543550
544551 addr_info_size = max_info_size ;
545552 if (addr_info_size == 0 ) {
546553 free (addr_info );
547- HANDLE_ERROR ( __WASI_ERRNO_NOENT )
554+ return EAI_NONAME ;
548555 }
549556
550557 aibuf_res =
551558 (struct aibuf * )calloc (1 , addr_info_size * sizeof (struct aibuf ));
552559 if (!aibuf_res ) {
553560 free (addr_info );
554- HANDLE_ERROR ( __WASI_ERRNO_NOMEM )
561+ return EAI_MEMORY ;
555562 }
556563
557564 * res = & aibuf_res [0 ].ai ;
@@ -564,14 +571,14 @@ getaddrinfo(const char *node, const char *service, const struct addrinfo *hints,
564571 if (error != __WASI_ERRNO_SUCCESS ) {
565572 free (addr_info );
566573 free (aibuf_res );
567- HANDLE_ERROR (error )
574+ GAI_HANDLE_ERROR (error )
568575 }
569576 ai -> ai_next = i == addr_info_size - 1 ? NULL : & aibuf_res [i + 1 ].ai ;
570577 }
571578
572579 free (addr_info );
573580
574- return __WASI_ERRNO_SUCCESS ;
581+ return 0 ;
575582}
576583
577584void
0 commit comments