From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from krisdoz.my.domain (schwarze@localhost [127.0.0.1]) by krisdoz.my.domain (8.14.5/8.14.5) with ESMTP id s7HKrod3015494 for ; Sun, 17 Aug 2014 16:53:50 -0400 (EDT) Received: (from schwarze@localhost) by krisdoz.my.domain (8.14.5/8.14.3/Submit) id s7HKrodN025877; Sun, 17 Aug 2014 16:53:50 -0400 (EDT) Date: Sun, 17 Aug 2014 16:53:50 -0400 (EDT) Message-Id: <201408172053.s7HKrodN025877@krisdoz.my.domain> X-Mailinglist: mdocml-source Reply-To: source@mdocml.bsd.lv MIME-Version: 1.0 From: schwarze@mdocml.bsd.lv To: source@mdocml.bsd.lv Subject: mdocml: Do not require getsubopt() to provide extern char *suboptarg. X-Mailer: activitymail 1.26, http://search.cpan.org/dist/activitymail/ Content-Type: text/plain; charset=utf-8 Log Message: ----------- Do not require getsubopt() to provide extern char *suboptarg. We don't use it anyway in mandoc. Like this, fewer systems need the compat implementation. In particular, we can now use the stock getsubopt() on glibc and musl. Besides, the comment in the BSD getsubopt.c that error messages are tricky without *suboptarg is massively overblown. If you simply save a copy of the pointer you pass into getsubopt(), that's quite usable for an error message. People start campaigning for the addition of *suboptarg to C libraries on the grounds that mandoc wants it, but actually, i consider library functions manipulating global data quite ugly, so stop pushing people into that questionable direction. While here, add an explicit Copyright header to the test file. While it's obviously to me what Kristaps intended, others might consider this file copyrightable and wonder what's up. Modified Files: -------------- mdocml: configure test-getsubopt.c compat_getsubopt.c Revision Data ------------- Index: test-getsubopt.c =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/test-getsubopt.c,v retrieving revision 1.2 retrieving revision 1.3 diff -Ltest-getsubopt.c -Ltest-getsubopt.c -u -p -r1.2 -r1.3 --- test-getsubopt.c +++ test-getsubopt.c @@ -1,11 +1,26 @@ +/* $Id$ */ +/* + * Copyright (c) 2011 Kristaps Dzonsons + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + #if defined(__linux__) || defined(__MINT__) -# define _GNU_SOURCE /* getsubopt() */ +#define _GNU_SOURCE /* getsubopt() */ #endif #include -extern char *suboptarg; - int main(void) { @@ -15,5 +30,5 @@ main(void) char *const tokens[] = { token0, NULL }; char *value = NULL; return( ! (0 == getsubopt(&options, tokens, &value) - && suboptarg == buf && value == buf+2 && options == buf+3)); + && value == buf+2 && options == buf+3)); } Index: configure =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/configure,v retrieving revision 1.12 retrieving revision 1.13 diff -Lconfigure -Lconfigure -u -p -r1.12 -r1.13 --- configure +++ configure @@ -305,10 +305,8 @@ __HEREDOC__ [ ${HAVE_FGETLN} -eq 0 ] && \ echo "extern char *fgetln(FILE *, size_t *);" -if [ ${HAVE_GETSUBOPT} -eq 0 ]; then +[ ${HAVE_GETSUBOPT} -eq 0 ] && \ echo "extern int getsubopt(char **, char * const *, char **);" - echo "extern char *suboptarg;" -fi [ ${HAVE_REALLOCARRAY} -eq 0 ] && \ echo "extern void *reallocarray(void *, size_t, size_t);" Index: compat_getsubopt.c =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/compat_getsubopt.c,v retrieving revision 1.4 retrieving revision 1.5 diff -Lcompat_getsubopt.c -Lcompat_getsubopt.c -u -p -r1.4 -r1.5 --- compat_getsubopt.c +++ compat_getsubopt.c @@ -6,6 +6,7 @@ int dummy; #else +/* $Id$ */ /* $OpenBSD: getsubopt.c,v 1.4 2005/08/08 08:05:36 espie Exp $ */ /*- @@ -41,18 +42,11 @@ int dummy; #include #include -/* - * The SVID interface to getsubopt provides no way of figuring out which - * part of the suboptions list wasn't matched. This makes error messages - * tricky... The extern variable suboptarg is a pointer to the token - * which didn't match. - */ -char *suboptarg; - int getsubopt(char **optionp, char * const *tokens, char **valuep) { int cnt; + char *suboptarg; char *p; suboptarg = *valuep = NULL; -- To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv