From: Reginald Kennedy Date: Wed, 25 Jul 2012 22:45:40 +0000 (+0800) Subject: Get actual LOGIN_NAME_MAX value from sysconf. X-Git-Url: https://jasonwoof.com/gitweb/?a=commitdiff_plain;ds=sidebyside;h=cbdd9e7fed98c7bb49ac2307b3a0651f01baed0c;p=spectrwm.git Get actual LOGIN_NAME_MAX value from sysconf. --- diff --git a/spectrwm.c b/spectrwm.c index 4ded077..0be0227 100644 --- a/spectrwm.c +++ b/spectrwm.c @@ -701,8 +701,8 @@ char * expand_tilde(char *s) { struct passwd *pwd; - int i; - char user[LOGIN_NAME_MAX]; + int i, max; + char *user; const char *sc = s; char *result; @@ -715,6 +715,13 @@ expand_tilde(char *s) } ++s; + + if ((max = sysconf(_SC_LOGIN_NAME_MAX)) == -1) + errx(1, "expand_tilde: sysconf"); + + if ((user = calloc(1, max + 1)) == NULL) + errx(1, "expand_tilde: calloc"); + for (i = 0; s[i] != '/' && s[i] != '\0'; ++i) user[i] = s[i]; user[i] = '\0';