About sysconf(_SC_GETPW_R_SIZE_MAX)

Konstantin Belousov kostikbel at gmail.com
Fri Jul 4 15:20:30 UTC 2014


On Fri, Jul 04, 2014 at 06:17:18PM +0400, Dmitry Sivachenko wrote:
> 
> On 04 июля 2014 г., at 17:00, Konstantin Belousov <kostikbel at gmail.com> wrote:
> 
> > On Fri, Jul 04, 2014 at 11:05:46AM +0400, Dmitry Sivachenko wrote:
> >> Hello!
> >> 
> >> (FreeBSD-10/stable).
> >> 
> >> According to sysconf(3), _SC_GETPW_R_SIZE_MAX is the valid argument to sysconf():
> >> 
> >> _SC_GETPW_R_SIZE_MAX
> >>             Suggested initial value for the size of the password entry
> >>             buffer.
> >> 
> >> But the following test program fails:
> >> 
> >> #include <unistd.h>
> >> #include <err.h>
> >> #include <errno.h>
> >> #include <stdio.h>
> >> 
> >> int main() {
> >>  int buf_sz;
> >> 
> >>  errno=0;
> >>  buf_sz = sysconf(_SC_GETPW_R_SIZE_MAX);
> >>  printf("%d\n", buf_sz);
> >>  warn("sysconf: ");
> >>  return 0;
> >> }
> >> 
> >> % ./a.out 
> >> -1
> >> a.out: sysconf: : Invalid argument
> >> 
> >> 
> >> What is wrong?
> > 
> > From lib/libc/gen/sysconf.c, around line 327:
> > #if _POSIX_THREAD_SAFE_FUNCTIONS > -1
> > 	case _SC_GETGR_R_SIZE_MAX:
> > 	case _SC_GETPW_R_SIZE_MAX:
> > #error "somebody needs to implement this"
> > #endif
> 
> 
> May be remove these two from man page?

I suppose it is better to implement them, trivially:

diff --git a/lib/libc/gen/sysconf.c b/lib/libc/gen/sysconf.c
index b7952b1..2b3acfb 100644
--- a/lib/libc/gen/sysconf.c
+++ b/lib/libc/gen/sysconf.c
@@ -367,11 +367,17 @@ yesno:
 		 * _POSIX_FILE_LOCKING, so we can't answer this one.
 		 */
 #endif
-#if _POSIX_THREAD_SAFE_FUNCTIONS > -1
+
+	/*
+	 * SUSv4tc1 says the following about _SC_GETGR_R_SIZE_MAX and
+	 * _SC_GETPW_R_SIZE_MAX:
+	 * Note that sysconf(_SC_GETGR_R_SIZE_MAX) may return -1 if
+	 * there is no hard limit on the size of the buffer needed to
+	 * store all the groups returned.
+	 */
 	case _SC_GETGR_R_SIZE_MAX:
 	case _SC_GETPW_R_SIZE_MAX:
-#error "somebody needs to implement this"
-#endif
+		return (-1);
 	case _SC_HOST_NAME_MAX:
 		return (MAXHOSTNAMELEN - 1); /* does not include \0 */
 	case _SC_LOGIN_NAME_MAX:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/freebsd-standards/attachments/20140704/d7b62cbb/attachment.sig>


More information about the freebsd-standards mailing list