]> code.delx.au - spectrwm/commitdiff
Get actual LOGIN_NAME_MAX value from sysconf.
authorReginald Kennedy <rk@rejii.com>
Wed, 25 Jul 2012 22:45:40 +0000 (06:45 +0800)
committerReginald Kennedy <rk@rejii.com>
Wed, 25 Jul 2012 22:45:40 +0000 (06:45 +0800)
spectrwm.c

index 4ded07705e776ca047170fa69b3cdaef9c2ad59b..0be0227de633db0e727adaf0d87ee447a8093eca 100644 (file)
@@ -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';