Simplify code that produces realname from gecos, replace strmcat() with strlcat().
git-svn-id: svn://svn.code.sf.net/p/bitchx/code/trunk@319 13b04d17-f746-0410-82c6-800466cd88b0
This commit is contained in:
33
source/irc.c
33
source/irc.c
@@ -1063,23 +1063,28 @@ static char *parse_args (char *argv[], int argc, char **envp)
|
|||||||
{
|
{
|
||||||
#ifdef GECOS_DELIMITER
|
#ifdef GECOS_DELIMITER
|
||||||
if ((ptr = strchr(entry->pw_gecos, GECOS_DELIMITER)))
|
if ((ptr = strchr(entry->pw_gecos, GECOS_DELIMITER)))
|
||||||
*ptr = (char) 0;
|
*ptr = 0;
|
||||||
#endif
|
#endif
|
||||||
if ((ptr = strchr(entry->pw_gecos, '&')) == NULL)
|
/* The first '&' character in pw_gecos is replaced with pw_name */
|
||||||
strlcpy(realname, entry->pw_gecos, sizeof realname);
|
if ((ptr = strchr(entry->pw_gecos, '&')))
|
||||||
else {
|
*ptr = 0;
|
||||||
int len = ptr - entry->pw_gecos;
|
|
||||||
|
|
||||||
if (len < REALNAME_LEN && *(entry->pw_name)) {
|
strlcpy(realname, entry->pw_gecos, sizeof realname);
|
||||||
char *q = realname + len;
|
|
||||||
|
|
||||||
strlcpy(realname, entry->pw_gecos, len);
|
if (ptr)
|
||||||
strmcat(realname, entry->pw_name, REALNAME_LEN);
|
{
|
||||||
strmcat(realname, ptr + 1, REALNAME_LEN);
|
size_t len = ptr - entry->pw_gecos;
|
||||||
if (islower((unsigned char)*q) && (q == realname || isspace((unsigned char)*(q - 1))))
|
|
||||||
*q = toupper(*q);
|
strlcat(realname, entry->pw_name, sizeof realname);
|
||||||
} else
|
strlcat(realname, ptr + 1, sizeof realname);
|
||||||
strlcpy(realname, entry->pw_gecos, sizeof realname);
|
|
||||||
|
/* Make the first character of the username uppercase, if
|
||||||
|
it's preceeded by a space */
|
||||||
|
if (len < sizeof realname && *(entry->pw_name) &&
|
||||||
|
(len == 0 || isspace((unsigned char)realname[len - 1])))
|
||||||
|
{
|
||||||
|
realname[len] = toupper((unsigned char)realname[len]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (entry->pw_name && *(entry->pw_name) && !*username)
|
if (entry->pw_name && *(entry->pw_name) && !*username)
|
||||||
|
|||||||
Reference in New Issue
Block a user