create: Merge in welcome crash fixes from master

This commit is contained in:
Andy Williams 2015-02-23 21:58:39 +00:00
parent 71fa2d13c8
commit 35f225292e
1 changed files with 29 additions and 16 deletions

View File

@ -233,24 +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;
errno = 0; if (!username)
p = getpwnam(username); return -1;
if (p == NULL && errno == 0)
return 0;
if (p == NULL)
return -1;
n = strcspn(p->pw_gecos, ","); errno = 0;
if (max == 0 || n <= 0) p = getpwnam(username);
return 0; if (p == NULL || max == 0)
if (n > max - 1) {
n = max - 1; if (errno == 0)
memcpy(fullname, p->pw_gecos, n); return 0;
fullname[n] = '\0'; else
return 1; return -1;
}
pos = strchr(p->pw_gecos, ',');
if (!pos)
n = strlen(p->pw_gecos);
else
n = pos - p->pw_gecos;
if (n == 0)
return 0;
if (n > max - 1)
n = max - 1;
memcpy(fullname, p->pw_gecos, n);
fullname[n] = '\0';
return 1;
} }
static void static void