diff options
author | Alexander Botero-Lowry <alex.boterolowry@gmail.com> | 2009-11-17 11:30:39 -0800 |
---|---|---|
committer | Carl Worth <cworth@cworth.org> | 2009-11-17 12:27:49 -0800 |
commit | 8177dc5d40fe0556c5832439ae10f2586af7c1b2 (patch) | |
tree | d3fd1a90bd6ec37a3474b854fcbd8cc414a2e058 /notmuch-config.c | |
parent | 12d3014d88737745d2b63d17b8b90f7553a242e1 (diff) |
Deal with situation where sysconf(_SC_GETPW_R_SIZE_MAX) returns -1
Diffstat (limited to 'notmuch-config.c')
-rw-r--r-- | notmuch-config.c | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/notmuch-config.c b/notmuch-config.c index 248149c8..7252a191 100644 --- a/notmuch-config.c +++ b/notmuch-config.c @@ -80,8 +80,17 @@ get_name_from_passwd_file (void *ctx) char *pw_buf = talloc_zero_size (ctx, pw_buf_size); struct passwd passwd, *ignored; char *name; + int e; - if (getpwuid_r (getuid (), &passwd, pw_buf, pw_buf_size, &ignored) == 0) { + if (pw_buf_size == -1) pw_buf_size = 64; + + while ((e = getpwuid_r (getuid (), &passwd, pw_buf, + pw_buf_size, &ignored)) == ERANGE) { + pw_buf_size = pw_buf_size * 2; + pw_buf = talloc_zero_size(ctx, pw_buf_size); + } + + if (e == 0) { char *comma = strchr (passwd.pw_gecos, ','); if (comma) name = talloc_strndup (ctx, passwd.pw_gecos, @@ -104,8 +113,16 @@ get_username_from_passwd_file (void *ctx) char *pw_buf = talloc_zero_size (ctx, pw_buf_size); struct passwd passwd, *ignored; char *name; + int e; + + if (pw_buf_size == -1) pw_buf_size = 64; + while ((e = getpwuid_r (getuid (), &passwd, pw_buf, + pw_buf_size, &ignored)) == ERANGE) { + pw_buf_size = pw_buf_size * 2; + pw_buf = talloc_zero_size(ctx, pw_buf_size); + } - if (getpwuid_r (getuid (), &passwd, pw_buf, pw_buf_size, &ignored) == 0) + if (e == 0) name = talloc_strdup (ctx, passwd.pw_name); else name = talloc_strdup (ctx, ""); |