aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorKaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>2017-04-12 00:58:46 +0300
committerDenys Vlasenko <vda.linux@googlemail.com>2017-04-12 20:11:34 +0200
commit835ad3a984c5590ae4f6c94f2f0781ea049d1ae8 (patch)
treecb86c5441c258f66358faa93ef899e09a7788de8 /include
parentc5496d3585bcab3c39f9b10f638ba0c94f5cda3f (diff)
downloadbusybox-w32-835ad3a984c5590ae4f6c94f2f0781ea049d1ae8.tar.gz
busybox-w32-835ad3a984c5590ae4f6c94f2f0781ea049d1ae8.tar.bz2
busybox-w32-835ad3a984c5590ae4f6c94f2f0781ea049d1ae8.zip
libbb: GETOPT_RESET macro
Signed-off-by: Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'include')
-rw-r--r--include/libbb.h22
1 files changed, 22 insertions, 0 deletions
diff --git a/include/libbb.h b/include/libbb.h
index 2c30bde6f..11d022fb5 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -1178,6 +1178,28 @@ extern uint32_t option_mask32;
1178extern uint32_t getopt32(char **argv, const char *applet_opts, ...) FAST_FUNC; 1178extern uint32_t getopt32(char **argv, const char *applet_opts, ...) FAST_FUNC;
1179 1179
1180 1180
1181/* BSD-derived getopt() functions require that optind be set to 1 in
1182 * order to reset getopt() state. This used to be generally accepted
1183 * way of resetting getopt(). However, glibc's getopt()
1184 * has additional getopt() state beyond optind (specifically, glibc
1185 * extensions ('+' and '-' at the start of the string), and requires
1186 * that optind be set to zero to reset its state. BSD-derived versions
1187 * of getopt() misbehaved if optind is set to 0 in order to reset getopt(),
1188 * and glibc's getopt() used to coredump if optind is set 1 in order
1189 * to reset getopt().
1190 * Then BSD introduced additional variable "optreset" which
1191 * be set to 1 in order to reset getopt(). Sigh. Standards, anyone?
1192 *
1193 * By ~2008, OpenBSD 3.4 was changed to survive glibc-like optind = 0
1194 * (to interpret it as if optreset was set).
1195 */
1196#ifdef __GLIBC__
1197#define GETOPT_RESET() (optind = 0)
1198#else /* BSD style */
1199#define GETOPT_RESET() (optind = 1)
1200#endif
1201
1202
1181/* Having next pointer as a first member allows easy creation 1203/* Having next pointer as a first member allows easy creation
1182 * of "llist-compatible" structs, and using llist_FOO functions 1204 * of "llist-compatible" structs, and using llist_FOO functions
1183 * on them. 1205 * on them.