1313#include " src/__support/common.h"
1414#include " src/__support/macros/config.h"
1515
16+ #include " src/errno/libc_errno.h"
1617#include " src/string/strlen.h"
1718#include " src/string/strncpy.h"
18- #include " src/errno/libc_errno.h"
1919
2020#include < sys/syscall.h> // For syscall numbers.
2121#include < sys/utsname.h>
@@ -25,7 +25,6 @@ namespace LIBC_NAMESPACE_DECL {
2525// Matching the behavior of glibc version 2.2 and later.
2626// Copies up to len bytes from the returned nodename field into name.
2727LLVM_LIBC_FUNCTION (int , gethostname, (char *name, size_t len)) {
28-
2928 // Check for invalid pointer
3029 if (name == nullptr ) {
3130 libc_errno = EFAULT;
@@ -35,18 +34,19 @@ LLVM_LIBC_FUNCTION(int, gethostname, (char *name, size_t len)) {
3534 struct utsname unameData;
3635 int ret = LIBC_NAMESPACE::syscall_impl<int >(SYS_uname, &unameData);
3736
38- // Checks if the length of the nodename was greater than or equal to len, and if it is,
39- // then the function returns -1 with errno set to ENAMETOOLONG.
40- // In this case, a terminating null byte is not included in the returned name.
41- if (strlen (unameData.nodename ) >= len)
42- {
37+ // Checks if the length of the nodename was greater than or equal to len, and
38+ // if it is, then the function returns -1 with errno set to ENAMETOOLONG. In
39+ // this case, a terminating null byte is not included in the returned name.
40+ if (strlen (unameData.nodename ) >= len) {
4341 strncpy (name, unameData.nodename , len);
4442 libc_errno = ENAMETOOLONG;
4543 return -1 ;
4644 }
4745
48- // If the size of the array name is not large enough (less than the size of nodename with null termination), then anything might happen.
49- // In this case, what happens to the array name will be determined by the implementation of LIBC_NAMESPACE_DECL::strncpy
46+ // If the size of the array name is not large enough (less than the size of
47+ // nodename with null termination), then anything might happen. In this case,
48+ // what happens to the array name will be determined by the implementation of
49+ // LIBC_NAMESPACE_DECL::strncpy
5050 strncpy (name, unameData.nodename , len);
5151
5252 if (ret < 0 ) {
@@ -58,5 +58,3 @@ LLVM_LIBC_FUNCTION(int, gethostname, (char *name, size_t len)) {
5858}
5959
6060} // namespace LIBC_NAMESPACE_DECL
61-
62-
0 commit comments