create: Replace user lookup with a more efficient implementation
This commit is contained in:
parent
de04dec6c0
commit
632ed0aa11
|
@ -233,27 +233,37 @@ _edi_welcome_project_new_create_cb(void *data EINA_UNUSED, Evas_Object *obj EINA
|
||||||
static int
|
static int
|
||||||
_edi_welcome_user_fullname_get(const char *username, char *fullname, size_t max)
|
_edi_welcome_user_fullname_get(const char *username, char *fullname, size_t max)
|
||||||
{
|
{
|
||||||
struct passwd *p;
|
struct passwd *p;
|
||||||
size_t n;
|
char *pos;
|
||||||
|
unsigned int n;
|
||||||
|
|
||||||
if (!username)
|
if (!username)
|
||||||
return 0;
|
return -1;
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
p = getpwnam(username);
|
p = getpwnam(username);
|
||||||
if (p == NULL && errno == 0)
|
if (p == NULL || max == 0)
|
||||||
return 0;
|
{
|
||||||
if (p == NULL)
|
if (errno == 0)
|
||||||
return -1;
|
return 0;
|
||||||
|
else
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
n = strcspn(p->pw_gecos, ",");
|
pos = strchr(p->pw_gecos, ',');
|
||||||
if (max == 0 || n <= 0)
|
if (!pos)
|
||||||
return 0;
|
n = strlen(p->pw_gecos);
|
||||||
if (n > max - 1)
|
else
|
||||||
n = max - 1;
|
n = pos - p->pw_gecos;
|
||||||
memcpy(fullname, p->pw_gecos, n);
|
|
||||||
fullname[n] = '\0';
|
if (n == 0)
|
||||||
return 1;
|
return 0;
|
||||||
|
if (n > max - 1)
|
||||||
|
n = max - 1;
|
||||||
|
|
||||||
|
memcpy(fullname, p->pw_gecos, n);
|
||||||
|
fullname[n] = '\0';
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
Loading…
Reference in New Issue