Various code cleanups

This commit is contained in:
Andrew Schwartzmeyer 2016-03-04 19:53:16 -08:00
parent 61667a43b5
commit 86801f0457
5 changed files with 12 additions and 18 deletions

View file

@ -12,7 +12,7 @@
//!
//! @exception errno Passes these errors via errno to GetLastError:
//! - ERROR_INVALID_FUNCTION: getlogin_r() returned an unrecognized error code
//! - ERROR_INVALID_ADDRESS: buffer is an invalid address
//! - ERROR_INVALID_ADDRESS: buffer is an invalid address
//! - ERROR_GEN_FAILURE: buffer not large enough
//!
//! @retval username as UTF-8 string, or null if unsuccessful
@ -42,6 +42,4 @@ char* GetComputerName()
}
return strdup(computername.c_str());
}

View file

@ -4,6 +4,6 @@
PAL_BEGIN_EXTERNC
char* GetComputerName();
char *GetComputerName();
PAL_END_EXTERNC

View file

@ -12,7 +12,6 @@
//! @brief GetFullyQualifiedName retrieves the fully qualifed dns name of the host
//!
//! @exception errno Passes these errors via errno to GetLastError:
//! - ERROR_BAD_ENVIRONMENT: locale is not UTF-8 (from GetComputerName)
//! - ERROR_INVALID_FUNCTION: getlogin_r() returned an unrecognized error code (from GetComputerName)
//! - ERROR_INVALID_ADDRESS: buffer is an invalid address (from GetComputerName)
//! - ERROR_GEN_FAILURE: buffer not large enough (from GetComputerName)
@ -21,12 +20,12 @@
//! @retval username as UTF-8 string, or null if unsuccessful
//!
char* GetFullyQualifiedName()
char *GetFullyQualifiedName()
{
errno = 0;
char *computerName = GetComputerName();
if (NULL == computerName)
if (computerName == NULL)
{
return NULL;
}
@ -37,7 +36,6 @@ char* GetFullyQualifiedName()
}
struct addrinfo hints, *info;
int gai_result;
memset(&hints, 0, sizeof hints);
hints.ai_family = AF_UNSPEC; /*either IPV4 or IPV6*/
@ -45,12 +43,12 @@ char* GetFullyQualifiedName()
hints.ai_flags = AI_CANONNAME;
/* There are several ways to get the domain name:
* uname(2), gethostbyname(3), resolver(3), getdomainname(2),
* and getaddrinfo(3). Some of these are not portable, some aren't
* POSIX compliant, and some are being deprecated. Getaddrinfo seems
* to be the best choice right now.
* uname(2), gethostbyname(3), resolver(3), getdomainname(2),
* and getaddrinfo(3). Some of these are not portable, some aren't
* POSIX compliant, and some are being deprecated. getaddrinfo seems
* to be the best choice.
*/
if ((gai_result = getaddrinfo(computerName, "http", &hints, &info)) != 0)
if (getaddrinfo(computerName, "http", &hints, &info) != 0)
{
errno = ERROR_BAD_NET_NAME;
return NULL;
@ -58,10 +56,9 @@ char* GetFullyQualifiedName()
// info is actually a link-list. We'll just return the first full name
char *fullName = strdup(info->ai_canonname);
char *fullName = strndup(info->ai_canonname, strlen(info->ai_canonname));
freeaddrinfo(info);
free(computerName);
return fullName;
}

View file

@ -4,6 +4,6 @@
PAL_BEGIN_EXTERNC
char* GetFullyQualifiedName();
char *GetFullyQualifiedName();
PAL_END_EXTERNC

View file

@ -101,5 +101,4 @@ int32_t GetLinkCount(const char* fileName, int32_t *count)
*count = statBuf.st_nlink;
return 1;
}