Skip to content

Commit 247a96e

Browse files
committed
address review comments
1 parent 67fbf2e commit 247a96e

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

libc/src/arpa/inet/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ add_entrypoint_object(
3333
libc.include.llvm-libc-types.in_addr
3434
libc.src.__support.common
3535
libc.src.__support.str_to_integer
36-
libc.src.arpa.inet.htonl
3736
)
3837

3938
add_entrypoint_object(

libc/src/arpa/inet/inet_aton.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
#include "src/arpa/inet/inet_aton.h"
1010
#include "src/__support/common.h"
11+
#include "src/__support/endian_internal.h"
1112
#include "src/__support/str_to_integer.h"
12-
#include "src/arpa/inet/htonl.h"
1313

1414
namespace LIBC_NAMESPACE_DECL {
1515

@@ -33,29 +33,34 @@ LLVM_LIBC_FUNCTION(int, inet_aton, (const char *cp, in_addr *inp)) {
3333
}
3434

3535
unsigned long result = 0;
36-
if (dot_num == 0) {
36+
switch (dot_num) {
37+
case 0:
3738
if (parts[0] > 0xffffffff)
3839
return 0;
3940
result = parts[0];
40-
} else if (dot_num == 1) {
41+
break;
42+
case 1:
4143
if (parts[0] > 0xff || parts[1] > 0xffffff)
4244
return 0;
4345
result = (parts[0] << 24) | parts[1];
44-
} else if (dot_num == 2) {
46+
break;
47+
case 2:
4548
if (parts[0] > 0xff || parts[1] > 0xff || parts[2] > 0xffff)
4649
return 0;
4750
result = (parts[0] << 24) | (parts[1] << 16) | parts[2];
48-
} else if (dot_num == 3) {
51+
break;
52+
case 3:
4953
if (parts[0] > 0xff || parts[1] > 0xff || parts[2] > 0xff ||
5054
parts[3] > 0xff)
5155
return 0;
5256
result = (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8) | parts[3];
53-
} else {
57+
break;
58+
default:
5459
return 0;
5560
}
5661

5762
if (inp)
58-
inp->s_addr = LIBC_NAMESPACE::htonl(static_cast<uint32_t>(result));
63+
inp->s_addr = Endian::to_big_endian(static_cast<uint32_t>(result));
5964

6065
return 1;
6166
}

libc/test/src/arpa/inet/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ add_libc_unittest(
3232
libc_arpa_inet_unittests
3333
SRCS
3434
inet_aton_test.cpp
35-
CXX_STANDARD
36-
20
3735
DEPENDS
3836
libc.src.arpa.inet.htonl
3937
libc.src.arpa.inet.inet_aton

0 commit comments

Comments
 (0)