wxGetUserName() now returns only the user name, not the comments
wxGetHostName() returns host.domain now git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@801 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -120,15 +120,31 @@ bool wxGetHostName(char *buf, int sz)
|
|||||||
{
|
{
|
||||||
*buf = '\0';
|
*buf = '\0';
|
||||||
#if defined(__SVR4__) && !defined(__sgi)
|
#if defined(__SVR4__) && !defined(__sgi)
|
||||||
|
//KB: does this return the fully qualified host.domain name?
|
||||||
return (sysinfo(SI_HOSTNAME, buf, sz) != -1);
|
return (sysinfo(SI_HOSTNAME, buf, sz) != -1);
|
||||||
#else /* BSD Sockets */
|
#else /* BSD Sockets */
|
||||||
char name[255];
|
char name[255], domain[255];
|
||||||
struct hostent *h;
|
//struct hostent *h;
|
||||||
// Get hostname
|
// Get hostname
|
||||||
if (gethostname(name, sizeof(name)/sizeof(char)-1) == -1)
|
if (gethostname(name, sizeof(name)/sizeof(char)-1) == -1)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
if (getdomainname(domain, sizeof(domain)/sizeof(char)-1) == -1)
|
||||||
|
return FALSE;
|
||||||
// Get official full name of host
|
// Get official full name of host
|
||||||
strncpy(buf, (h=gethostbyname(name))!=NULL ? h->h_name : name, sz-1);
|
// doesn't return the full qualified name, replaced by following
|
||||||
|
// code (KB)
|
||||||
|
// strncpy(buf, (h=gethostbyname(name))!=NULL ? h->h_name : name, sz-1);
|
||||||
|
if((unsigned)sz > strlen(name)+strlen(domain)+1)
|
||||||
|
{
|
||||||
|
strcpy(buf, name);
|
||||||
|
if(strcmp(domain,"(none)") == 0) // standalone machine
|
||||||
|
{
|
||||||
|
strcat(buf,".");
|
||||||
|
strcat(buf,domain);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return FALSE;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -148,9 +164,12 @@ bool wxGetUserId(char *buf, int sz)
|
|||||||
bool wxGetUserName(char *buf, int sz)
|
bool wxGetUserName(char *buf, int sz)
|
||||||
{
|
{
|
||||||
struct passwd *who;
|
struct passwd *who;
|
||||||
|
char *comma;
|
||||||
|
|
||||||
*buf = '\0';
|
*buf = '\0';
|
||||||
if ((who = getpwuid (getuid ())) != NULL) {
|
if ((who = getpwuid (getuid ())) != NULL) {
|
||||||
|
comma = strchr(who->pw_gecos,'c');
|
||||||
|
if(comma) *comma = '\0'; // cut off non-name comment fields
|
||||||
strncpy (buf, who->pw_gecos, sz - 1);
|
strncpy (buf, who->pw_gecos, sz - 1);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@@ -120,15 +120,31 @@ bool wxGetHostName(char *buf, int sz)
|
|||||||
{
|
{
|
||||||
*buf = '\0';
|
*buf = '\0';
|
||||||
#if defined(__SVR4__) && !defined(__sgi)
|
#if defined(__SVR4__) && !defined(__sgi)
|
||||||
|
//KB: does this return the fully qualified host.domain name?
|
||||||
return (sysinfo(SI_HOSTNAME, buf, sz) != -1);
|
return (sysinfo(SI_HOSTNAME, buf, sz) != -1);
|
||||||
#else /* BSD Sockets */
|
#else /* BSD Sockets */
|
||||||
char name[255];
|
char name[255], domain[255];
|
||||||
struct hostent *h;
|
//struct hostent *h;
|
||||||
// Get hostname
|
// Get hostname
|
||||||
if (gethostname(name, sizeof(name)/sizeof(char)-1) == -1)
|
if (gethostname(name, sizeof(name)/sizeof(char)-1) == -1)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
if (getdomainname(domain, sizeof(domain)/sizeof(char)-1) == -1)
|
||||||
|
return FALSE;
|
||||||
// Get official full name of host
|
// Get official full name of host
|
||||||
strncpy(buf, (h=gethostbyname(name))!=NULL ? h->h_name : name, sz-1);
|
// doesn't return the full qualified name, replaced by following
|
||||||
|
// code (KB)
|
||||||
|
// strncpy(buf, (h=gethostbyname(name))!=NULL ? h->h_name : name, sz-1);
|
||||||
|
if((unsigned)sz > strlen(name)+strlen(domain)+1)
|
||||||
|
{
|
||||||
|
strcpy(buf, name);
|
||||||
|
if(strcmp(domain,"(none)") == 0) // standalone machine
|
||||||
|
{
|
||||||
|
strcat(buf,".");
|
||||||
|
strcat(buf,domain);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return FALSE;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -148,9 +164,12 @@ bool wxGetUserId(char *buf, int sz)
|
|||||||
bool wxGetUserName(char *buf, int sz)
|
bool wxGetUserName(char *buf, int sz)
|
||||||
{
|
{
|
||||||
struct passwd *who;
|
struct passwd *who;
|
||||||
|
char *comma;
|
||||||
|
|
||||||
*buf = '\0';
|
*buf = '\0';
|
||||||
if ((who = getpwuid (getuid ())) != NULL) {
|
if ((who = getpwuid (getuid ())) != NULL) {
|
||||||
|
comma = strchr(who->pw_gecos,'c');
|
||||||
|
if(comma) *comma = '\0'; // cut off non-name comment fields
|
||||||
strncpy (buf, who->pw_gecos, sz - 1);
|
strncpy (buf, who->pw_gecos, sz - 1);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user