Print this page
2989 Eliminate use of LOGNAME_MAX in ON
1166 useradd have warning with name more 8 chars

*** 17,26 **** --- 17,28 ---- * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* + * Copyright (c) 2013 Gary Mills + * * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. * * Portions Copyright 2009 Chad Mynhier */
*** 33,42 **** --- 35,45 ---- #include <string.h> #include <libintl.h> #include <errno.h> #include <zone.h> #include <libzonecfg.h> + #include <wchar.h> #include "prstat.h" #include "prutil.h" #include "prtable.h"
*** 57,73 **** Die(gettext("invalid user name: %s\n"), name); return (pwd->pw_uid); } void ! pwd_getname(uid_t uid, char *name, int length, int noresolve) { struct passwd *pwd; if (noresolve || (pwd = getpwuid(uid)) == NULL) { (void) snprintf(name, length, "%u", uid); } else { (void) snprintf(name, length, "%s", pwd->pw_name); } } void --- 60,90 ---- Die(gettext("invalid user name: %s\n"), name); return (pwd->pw_uid); } void ! pwd_getname(uid_t uid, char *name, size_t length, int noresolve, ! int trunc, size_t width) { struct passwd *pwd; + size_t n; if (noresolve || (pwd = getpwuid(uid)) == NULL) { + n = snprintf(NULL, 0, "%u", uid); + if (trunc && n > width) + (void) snprintf(name, length, "%.*u%c", + width - 1, uid, '*'); + else (void) snprintf(name, length, "%u", uid); } else { + n = mbstowcs(NULL, pwd->pw_name, 0); + if (n == (size_t)-1) + (void) snprintf(name, length, "%s", "ERROR"); + else if (trunc && n > width) + (void) snprintf(name, length, "%.*s%c", + width - 1, pwd->pw_name, '*'); + else (void) snprintf(name, length, "%s", pwd->pw_name); } } void