From: Harlan Stenn Date: Thu, 1 Aug 2013 02:03:52 +0000 (+0000) Subject: Upgrade to libopts-40.1.15 X-Git-Tag: NTP_4_2_7P378~2^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f15165003b7fdb338913e84568f1e0cbaf5527e7;p=thirdparty%2Fntp.git Upgrade to libopts-40.1.15 bk: 51f9c208s4wzIIsUDDN8UGtBmlo39A --- diff --git a/sntp/libopts/Makefile.am b/sntp/libopts/Makefile.am index 44c6d2728..fd879bea9 100644 --- a/sntp/libopts/Makefile.am +++ b/sntp/libopts/Makefile.am @@ -7,20 +7,20 @@ noinst_LTLIBRARIES = libopts.la endif libopts_la_SOURCES = libopts.c libopts_la_CPPFLAGS = -I$(top_srcdir) -libopts_la_LDFLAGS = -version-info 39:0:14 +libopts_la_LDFLAGS = -version-info 40:1:15 EXTRA_DIST = \ COPYING.gplv3 COPYING.lgplv3 COPYING.mbsd \ MakeDefs.inc README ag-char-map.h \ alias.c ao-strs.c ao-strs.h \ - autoopts/options.h autoopts/project.h autoopts/usage-txt.h \ + autoopts/usage-txt.h autoopts/project.h autoopts/options.h \ autoopts.c autoopts.h boolean.c \ - check.c compat/compat.h compat/snprintf.c \ - compat/pathfind.c compat/strdup.c compat/windows-config.h \ - compat/strchr.c configfile.c cook.c \ + check.c compat/windows-config.h compat/pathfind.c \ + compat/snprintf.c compat/strchr.c compat/compat.h \ + compat/strdup.c configfile.c cook.c \ enum.c env.c file.c \ find.c genshell.c genshell.h \ gettext.h init.c load.c \ - m4/libopts.m4 m4/liboptschk.m4 makeshell.c \ + m4/liboptschk.m4 m4/libopts.m4 makeshell.c \ nested.c numeric.c option-value-type.c \ option-value-type.h option-xat-attribute.c option-xat-attribute.h \ parse-duration.c parse-duration.h pgusage.c \ diff --git a/sntp/libopts/ag-char-map.h b/sntp/libopts/ag-char-map.h index bffb2f120..3b89fb700 100644 --- a/sntp/libopts/ag-char-map.h +++ b/sntp/libopts/ag-char-map.h @@ -1,6 +1,6 @@ /* * 29 bits for 46 character classifications - * generated by char-mapper on 07/05/13 at 20:32:35 + * generated by char-mapper on 07/28/13 at 08:25:15 * * This file contains the character classifications * used by AutoGen and AutoOpts for identifying tokens. @@ -489,7 +489,7 @@ spn_ag_char_map_chars(char const * p, unsigned int mask_ix) unsigned char const * v = ag_char_map_spanners[mask_ix]; if (v == NULL) v = calc_ag_char_map_spanners(mask_ix); - while (v[(unsigned)*p]) p++; + while (v[(unsigned char)*p]) p++; return (char *)(uintptr_t)p; } @@ -499,7 +499,7 @@ brk_ag_char_map_chars(char const * p, unsigned int mask_ix) unsigned char const * v = ag_char_map_spanners[mask_ix]; if (v == NULL) v = calc_ag_char_map_spanners(mask_ix); - while ((*p != '\0') && (! v[(unsigned)*p])) p++; + while ((*p != '\0') && (! v[(unsigned char)*p])) p++; return (char *)(uintptr_t)p; } @@ -510,7 +510,7 @@ spn_ag_char_map_back(char const * s, char const * e, unsigned int mask_ix) if (v == NULL) v = calc_ag_char_map_spanners(mask_ix); if (s >= e) e = s + strlen(s); - while ((e > s) && v[(unsigned)e[-1]]) e--; + while ((e > s) && v[(unsigned char)e[-1]]) e--; return (char *)(uintptr_t)e; } @@ -521,7 +521,7 @@ brk_ag_char_map_back(char const * s, char const * e, unsigned int mask_ix) if (v == NULL) v = calc_ag_char_map_spanners(mask_ix); if (s == e) e += strlen(e); - while ((e > s) && (! v[(unsigned)e[-1]])) e--; + while ((e > s) && (! v[(unsigned char)e[-1]])) e--; return (char *)(uintptr_t)e; } #endif /* AG_CHAR_MAP_H_GUARD */ diff --git a/sntp/libopts/ao-strs.c b/sntp/libopts/ao-strs.c index a80e78310..5ec883d78 100644 --- a/sntp/libopts/ao-strs.c +++ b/sntp/libopts/ao-strs.c @@ -2,7 +2,7 @@ * * DO NOT EDIT THIS FILE (ao-strs.c) * - * It has been AutoGen-ed July 5, 2013 at 08:32:35 PM by AutoGen 5.17.5pre9 + * It has been AutoGen-ed July 28, 2013 at 08:25:16 AM by AutoGen 5.18.1pre2 * From the definitions ao-strs.def * and the template file strings * diff --git a/sntp/libopts/ao-strs.h b/sntp/libopts/ao-strs.h index 696f3c3d6..1549d1044 100644 --- a/sntp/libopts/ao-strs.h +++ b/sntp/libopts/ao-strs.h @@ -2,7 +2,7 @@ * * DO NOT EDIT THIS FILE (ao-strs.h) * - * It has been AutoGen-ed July 5, 2013 at 08:32:35 PM by AutoGen 5.17.5pre9 + * It has been AutoGen-ed July 28, 2013 at 08:25:16 AM by AutoGen 5.18.1pre2 * From the definitions ao-strs.def * and the template file strings * diff --git a/sntp/libopts/autoopts.c b/sntp/libopts/autoopts.c index bbf27df56..966ea45a8 100644 --- a/sntp/libopts/autoopts.c +++ b/sntp/libopts/autoopts.c @@ -37,6 +37,28 @@ */ static unsigned int tab_skip_ct = 0; +#ifndef HAVE_PATHFIND +# define pathfind(_p, _n, _m) option_pathfind(_p, _n, _m) +# include "compat/pathfind.c" +#endif + +#ifndef HAVE_SNPRINTF +# define vsnprintf option_vsnprintf +# define snprintf option_snprintf +# include "compat/snprintf.c" +#endif + +#ifndef HAVE_STRDUP +# define strdup(_s) option_strdup(_s) +# include "compat/strdup.c" +#endif + +#ifndef HAVE_STRCHR +# define strrchr(_s, _c) option_strrchr(_s, _c) +# define strchr(_s, _c) option_strchr(_s, _c) +# include "compat/strchr.c" +#endif + LOCAL void * ao_malloc(size_t sz) { @@ -76,28 +98,6 @@ ao_strdup(char const *str) #undef strdup #define strdup(_p) ao_strdup(_p) -#ifndef HAVE_PATHFIND -# define pathfind(_p, _n, _m) option_pathfind(_p, _n, _m) -# include "compat/pathfind.c" -#endif - -#ifndef HAVE_SNPRINTF -# define vsnprintf option_vsnprintf -# define snprintf option_snprintf -# include "compat/snprintf.c" -#endif - -#ifndef HAVE_STRDUP -# define strdup(_s) option_strdup(_s) -# include "compat/strdup.c" -#endif - -#ifndef HAVE_STRCHR -# define strrchr(_s, _c) option_strrchr(_s, _c) -# define strchr(_s, _c) option_strchr(_s, _c) -# include "compat/strchr.c" -#endif - /** * handle an option. * diff --git a/sntp/libopts/autoopts.h b/sntp/libopts/autoopts.h index d66e7419b..7bb85a19b 100644 --- a/sntp/libopts/autoopts.h +++ b/sntp/libopts/autoopts.h @@ -129,8 +129,19 @@ #define SKIP_OPT(p) (((p)->fOptState & OPTST_IMMUTABLE_MASK) != 0) typedef int tDirection; +/** + * handling option presets. Start with command line and work through + * config settings in reverse order. + */ #define DIRECTION_PRESET -1 +/** + * handling normal options. Start with first config file, then environment + * variables and finally the command line. + */ #define DIRECTION_PROCESS 1 +/** + * An initialzation phase or an option being loaded from program sources. + */ #define DIRECTION_CALLED 0 #define PROCESSING(d) ((d)>0) diff --git a/sntp/libopts/autoopts/options.h b/sntp/libopts/autoopts/options.h index 36ec370fd..3c013fa42 100644 --- a/sntp/libopts/autoopts/options.h +++ b/sntp/libopts/autoopts/options.h @@ -2,7 +2,7 @@ * * DO NOT EDIT THIS FILE (options.h) * - * It has been AutoGen-ed July 5, 2013 at 08:32:42 PM by AutoGen 5.17.5pre9 + * It has been AutoGen-ed July 28, 2013 at 08:25:23 AM by AutoGen 5.18.1pre2 * From the definitions funcs.def * and the template file options_h * @@ -101,15 +101,15 @@ * @{ */ /// autoopts structure version -#define OPTIONS_STRUCT_VERSION 159744 +#define OPTIONS_STRUCT_VERSION 163841 /// autoopts structure version string -#define OPTIONS_VERSION_STRING "39:0:14" +#define OPTIONS_VERSION_STRING "40:1:15" /// minimum version the autoopts library supports #define OPTIONS_MINIMUM_VERSION 102400 /// minimum version the autoopts library supports as a string #define OPTIONS_MIN_VER_STRING "25:0:0" /// the display version of the autoopts library, as a string -#define OPTIONS_DOTTED_VERSION "39.0" +#define OPTIONS_DOTTED_VERSION "40.1" /// convert a version/release number pair to an integer value #define OPTIONS_VER_TO_NUM(_v, _r) (((_v) * 4096) + (_r)) /// @} diff --git a/sntp/libopts/autoopts/usage-txt.h b/sntp/libopts/autoopts/usage-txt.h index 383e9871d..d98904ca6 100644 --- a/sntp/libopts/autoopts/usage-txt.h +++ b/sntp/libopts/autoopts/usage-txt.h @@ -2,7 +2,7 @@ * * DO NOT EDIT THIS FILE (usage-txt.h) * - * It has been AutoGen-ed July 5, 2013 at 08:32:40 PM by AutoGen 5.17.5pre9 + * It has been AutoGen-ed July 28, 2013 at 08:25:20 AM by AutoGen 5.18.1pre2 * From the definitions usage-txt.def * and the template file usage-txt.tpl * @@ -362,9 +362,9 @@ do not compile this section. */ static void dummy_func(void) { /* LIBOPTS-MESSAGES: */ -#line 45 "../autoopts.c" +#line 67 "../autoopts.c" puts(_("allocation of %d bytes failed\n")); -#line 71 "../autoopts.c" +#line 93 "../autoopts.c" puts(_("allocation of %d bytes failed\n")); #line 53 "../init.c" puts(_("AutoOpts function called without option descriptor\n")); @@ -373,7 +373,7 @@ static void dummy_func(void) { #line 88 "../init.c" puts(_("Automated Options Processing Error!\n" "\t%s called AutoOpts function with structure version %d:%d:%d.\n")); -#line 58 "../autoopts.c" +#line 80 "../autoopts.c" puts(_("realloc of %d bytes at 0x%p failed\n")); #line 92 "../init.c" puts(_("\tThis is less than the minimum library version: ")); @@ -388,9 +388,9 @@ static void dummy_func(void) { puts(_("could not locate the 'help' option")); #line 336 "../autoopts.c" puts(_("optionProcess() was called with invalid data")); -#line 747 "../usage.c" +#line 748 "../usage.c" puts(_("invalid argument type specified")); -#line 589 "../find.c" +#line 598 "../find.c" puts(_("defaulted to option with optional arg")); #line 76 "../alias.c" puts(_("aliasing option is out of range.")); @@ -398,7 +398,7 @@ static void dummy_func(void) { puts(_("%s error: the keyword '%s' is ambiguous for %s\n")); #line 108 "../find.c" puts(_(" The following options match:\n")); -#line 290 "../find.c" +#line 293 "../find.c" puts(_("%s: ambiguous option name: %s (matches %d options)\n")); #line 161 "../check.c" puts(_("%s: Command line arguments required\n")); @@ -415,42 +415,42 @@ static void dummy_func(void) { "\t'n' - version and full copyright notice\n")); #line 58 "../check.c" puts(_("%s error: the '%s' and '%s' options conflict\n")); -#line 214 "../find.c" +#line 217 "../find.c" puts(_("%s: The '%s' option has been disabled.")); -#line 421 "../find.c" +#line 430 "../find.c" puts(_("%s: The '%s' option has been disabled.")); #line 38 "../alias.c" puts(_("-equivalence")); -#line 460 "../find.c" +#line 469 "../find.c" puts(_("%s: illegal option -- %c\n")); #line 110 "../reset.c" puts(_("%s: illegal option -- %c\n")); -#line 268 "../find.c" +#line 271 "../find.c" puts(_("%s: illegal option -- %s\n")); -#line 746 "../find.c" +#line 755 "../find.c" puts(_("%s: illegal option -- %s\n")); #line 118 "../reset.c" puts(_("%s: illegal option -- %s\n")); -#line 332 "../find.c" +#line 335 "../find.c" puts(_("%s: unknown vendor extension option -- %s\n")); #line 159 "../enum.c" puts(_(" or an integer from %d through %d\n")); #line 169 "../enum.c" puts(_(" or an integer from %d through %d\n")); -#line 746 "../usage.c" +#line 747 "../usage.c" puts(_("%s error: invalid option descriptor for %s\n")); -#line 1080 "../usage.c" +#line 1081 "../usage.c" puts(_("%s error: invalid option descriptor for %s\n")); -#line 379 "../find.c" +#line 385 "../find.c" puts(_("%s: invalid option name: %s\n")); -#line 518 "../find.c" +#line 527 "../find.c" puts(_("%s: The '%s' option requires an argument.\n")); #line 156 "../autoopts.c" puts(_("(AutoOpts bug): Equivalenced option '%s' was equivalenced to both\n" "\t'%s' and '%s'.")); #line 94 "../check.c" puts(_("%s error: The %s option is required\n")); -#line 623 "../find.c" +#line 632 "../find.c" puts(_("%s: The '%s' option cannot have an argument.\n")); #line 151 "../check.c" puts(_("%s: Command line arguments are not allowed.\n")); @@ -480,7 +480,7 @@ static void dummy_func(void) { puts(_("%s error: '%s' is not a recognizable number.\n")); #line 200 "../enum.c" puts(_("%s error: %s exceeds %s keyword count\n")); -#line 329 "../usage.c" +#line 330 "../usage.c" puts(_("Try '%s %s' for more information.\n")); #line 45 "../alias.c" puts(_("one %s%s option allowed\n")); @@ -490,17 +490,17 @@ static void dummy_func(void) { puts(_("standard output")); #line 274 "../usage.c" puts(_("standard output")); -#line 414 "../usage.c" +#line 415 "../usage.c" puts(_("standard output")); -#line 624 "../usage.c" +#line 625 "../usage.c" puts(_("standard output")); #line 175 "../version.c" puts(_("standard output")); #line 274 "../usage.c" puts(_("standard error")); -#line 414 "../usage.c" +#line 415 "../usage.c" puts(_("standard error")); -#line 624 "../usage.c" +#line 625 "../usage.c" puts(_("standard error")); #line 175 "../version.c" puts(_("standard error")); @@ -510,9 +510,9 @@ static void dummy_func(void) { puts(_("write")); #line 273 "../usage.c" puts(_("write")); -#line 413 "../usage.c" +#line 414 "../usage.c" puts(_("write")); -#line 623 "../usage.c" +#line 624 "../usage.c" puts(_("write")); #line 174 "../version.c" puts(_("write")); @@ -533,29 +533,29 @@ static void dummy_func(void) { /* END-LIBOPTS-MESSAGES */ /* USAGE-TEXT: */ -#line 872 "../usage.c" +#line 873 "../usage.c" puts(_("\t\t\t\t- an alternate for '%s'\n")); -#line 1147 "../usage.c" +#line 1148 "../usage.c" puts(_("Version, usage and configuration options:")); -#line 923 "../usage.c" +#line 924 "../usage.c" puts(_("\t\t\t\t- default option for unnamed options\n")); -#line 836 "../usage.c" +#line 837 "../usage.c" puts(_("\t\t\t\t- disabled as '--%s'\n")); -#line 1116 "../usage.c" +#line 1117 "../usage.c" puts(_(" --- %-14s %s\n")); -#line 1114 "../usage.c" +#line 1115 "../usage.c" puts(_("This option has been disabled")); -#line 863 "../usage.c" +#line 864 "../usage.c" puts(_("\t\t\t\t- enabled by default\n")); #line 40 "../alias.c" puts(_("%s error: only ")); -#line 1193 "../usage.c" +#line 1194 "../usage.c" puts(_(" - examining environment variables named %s_*\n")); #line 168 "../file.c" puts(_("\t\t\t\t- file must not pre-exist\n")); #line 172 "../file.c" puts(_("\t\t\t\t- file must pre-exist\n")); -#line 379 "../usage.c" +#line 380 "../usage.c" puts(_("Options are specified by doubled hyphens and their name or by a single\n" "hyphen and the flag character.\n")); #line 916 "../makeshell.c" @@ -565,33 +565,33 @@ static void dummy_func(void) { "a shell script to parse the options for %s:\n\n")); #line 166 "../enum.c" puts(_(" or an integer mask with any of the lower %d bits set\n")); -#line 896 "../usage.c" +#line 897 "../usage.c" puts(_("\t\t\t\t- is a set membership option\n")); -#line 917 "../usage.c" +#line 918 "../usage.c" puts(_("\t\t\t\t- must appear between %d and %d times\n")); -#line 381 "../usage.c" +#line 382 "../usage.c" puts(_("Options are specified by single or double hyphens and their name.\n")); -#line 903 "../usage.c" +#line 904 "../usage.c" puts(_("\t\t\t\t- may appear multiple times\n")); -#line 890 "../usage.c" +#line 891 "../usage.c" puts(_("\t\t\t\t- may not be preset\n")); -#line 1308 "../usage.c" +#line 1309 "../usage.c" puts(_(" Arg Option-Name Description\n")); -#line 1244 "../usage.c" - puts(_(" Flg Arg Option-Name Description\n")); -#line 1302 "../usage.c" +#line 1245 "../usage.c" puts(_(" Flg Arg Option-Name Description\n")); #line 1303 "../usage.c" + puts(_(" Flg Arg Option-Name Description\n")); +#line 1304 "../usage.c" puts(_(" %3s %s")); -#line 1309 "../usage.c" +#line 1310 "../usage.c" puts(_(" %3s %s")); -#line 386 "../usage.c" +#line 387 "../usage.c" puts(_("The '-#' option may omit the hash char\n")); -#line 382 "../usage.c" +#line 383 "../usage.c" puts(_("All arguments are named options.\n")); -#line 970 "../usage.c" +#line 971 "../usage.c" puts(_(" - reading file %s")); -#line 408 "../usage.c" +#line 409 "../usage.c" puts(_("\n" "Please send bug reports to: <%s>\n")); #line 100 "../version.c" @@ -600,17 +600,17 @@ static void dummy_func(void) { #line 129 "../version.c" puts(_("\n" "Please send bug reports to: <%s>\n")); -#line 902 "../usage.c" +#line 903 "../usage.c" puts(_("\t\t\t\t- may NOT appear - preset only\n")); -#line 943 "../usage.c" +#line 944 "../usage.c" puts(_("\n" "The following option preset mechanisms are supported:\n")); -#line 1191 "../usage.c" +#line 1192 "../usage.c" puts(_("\n" "The following option preset mechanisms are supported:\n")); -#line 681 "../usage.c" +#line 682 "../usage.c" puts(_("prohibits these options:\n")); -#line 676 "../usage.c" +#line 677 "../usage.c" puts(_("prohibits the option '%s'\n")); #line 81 "../numeric.c" puts(_("%s%ld to %ld")); @@ -628,28 +628,28 @@ static void dummy_func(void) { puts(_("%sis scalable with a suffix: k/K/m/M/g/G/t/T\n")); #line 77 "../numeric.c" puts(_("%sless than or equal to %ld")); -#line 389 "../usage.c" +#line 390 "../usage.c" puts(_("Operands and options may be intermixed. They will be reordered.\n")); -#line 651 "../usage.c" +#line 652 "../usage.c" puts(_("requires the option '%s'\n")); -#line 654 "../usage.c" +#line 655 "../usage.c" puts(_("requires these options:\n")); -#line 1320 "../usage.c" +#line 1321 "../usage.c" puts(_(" Arg Option-Name Req? Description\n")); -#line 1314 "../usage.c" +#line 1315 "../usage.c" puts(_(" Flg Arg Option-Name Req? Description\n")); #line 167 "../enum.c" puts(_("or you may use a numeric representation. Preceding these with a '!'\n" "will clear the bits, specifying 'none' will clear all bits, and 'all'\n" "will set them all. Multiple entries may be passed as an option\n" "argument list.\n")); -#line 909 "../usage.c" +#line 910 "../usage.c" puts(_("\t\t\t\t- may appear up to %d times\n")); #line 77 "../enum.c" puts(_("The valid \"%s\" option keywords are:\n")); -#line 1151 "../usage.c" +#line 1152 "../usage.c" puts(_("The next option supports vendor supported extra options:")); -#line 772 "../usage.c" +#line 773 "../usage.c" puts(_("These additional options are:")); /* END-USAGE-TEXT */ } diff --git a/sntp/libopts/compat/pathfind.c b/sntp/libopts/compat/pathfind.c index ec380bc8f..6554533d2 100644 --- a/sntp/libopts/compat/pathfind.c +++ b/sntp/libopts/compat/pathfind.c @@ -8,7 +8,7 @@ static char * pathfind( char const * path, - char const * fileName, + char const * fname, char const * mode ); #include "compat.h" @@ -16,10 +16,10 @@ pathfind( char const * path, #if defined(__windows__) && !defined(__CYGWIN__) static char * pathfind( char const * path, - char const * fileName, + char const * fname, char const * mode ) { - return NULL; + return strdup(fname); } #else @@ -27,70 +27,22 @@ static char* make_absolute( char const *string, char const *dot_path ); static char* canonicalize_pathname( char *path ); static char* extract_colon_unit( char* dir, char const *string, int *p_index ); - -/*=export_func pathfind - * - * what: fild a file in a list of directories - * - * ifndef: HAVE_PATHFIND - * - * arg: + char const* + path + colon separated list of search directories + - * arg: + char const* + file + the name of the file to look for + - * arg: + char const* + mode + the mode bits that must be set to match + - * - * ret_type: char* - * ret_desc: the path to the located file - * - * doc: - * - * pathfind looks for a a file with name "FILE" and "MODE" access - * along colon delimited "PATH", and returns the full pathname as a - * string, or NULL if not found. If "FILE" contains a slash, then - * it is treated as a relative or absolute path and "PATH" is ignored. - * - * @strong{NOTE}: this function is compiled into @file{libopts} only if - * it is not natively supplied. - * - * The "MODE" argument is a string of option letters chosen from the - * list below: - * @example - * Letter Meaning - * r readable - * w writable - * x executable - * f normal file (NOT IMPLEMENTED) - * b block special (NOT IMPLEMENTED) - * c character special (NOT IMPLEMENTED) - * d directory (NOT IMPLEMENTED) - * p FIFO (pipe) (NOT IMPLEMENTED) - * u set user ID bit (NOT IMPLEMENTED) - * g set group ID bit (NOT IMPLEMENTED) - * k sticky bit (NOT IMPLEMENTED) - * s size nonzero (NOT IMPLEMENTED) - * @end example - * - * example: - * To find the "ls" command using the "PATH" environment variable: - * @example - * #include - * char* pz_ls = pathfind( getenv("PATH"), "ls", "rx" ); - * <> - * free( pz_ls ); - * @end example - * The path is allocated with @code{malloc(3C)}, so you must @code{free(3C)} - * the result. Also, do not use unimplemented file modes. :-) - * - * err: returns NULL if the file is not found. -=*/ +/** + * local implementation of pathfind. + * @param[in] path colon separated list of directories + * @param[in] fname the name we are hunting for + * @param[in] mode the required file mode + * @returns an allocated string with the full path, or NULL + */ static char * pathfind( char const * path, - char const * fileName, + char const * fname, char const * mode ) { - int p_index = 0; - int mode_bits = 0; - char* pathName = NULL; - char zPath[ AG_PATH_MAX + 1 ]; + int p_index = 0; + int mode_bits = 0; + char * res_path = NULL; + char zPath[ AG_PATH_MAX + 1 ]; if (strchr( mode, 'r' )) mode_bits |= R_OK; if (strchr( mode, 'w' )) mode_bits |= W_OK; @@ -103,9 +55,6 @@ pathfind( char const * path, DIR* dirP; char* colon_unit = extract_colon_unit( zPath, path, &p_index ); - /* - * IF no more entries, THEN quit - */ if (colon_unit == NULL) break; @@ -117,9 +66,6 @@ pathfind( char const * path, if (dirP == NULL) continue; - /* - * FOR every entry in the given directory, ... - */ for (;;) { struct dirent *entP = readdir( dirP ); @@ -129,31 +75,31 @@ pathfind( char const * path, /* * IF the file name matches the one we are looking for, ... */ - if (strcmp( entP->d_name, fileName ) == 0) { - char* pzFullName = make_absolute( fileName, colon_unit); + if (strcmp(entP->d_name, fname) == 0) { + char * abs_name = make_absolute(fname, colon_unit); /* * Make sure we can access it in the way we want */ - if (access( pzFullName, mode_bits ) >= 0) { + if (access(abs_name, mode_bits) >= 0) { /* * We can, so normalize the name and return it below */ - pathName = canonicalize_pathname( pzFullName ); + res_path = canonicalize_pathname(abs_name); } - free( (void*)pzFullName ); + free(abs_name); break; } } closedir( dirP ); - if (pathName != NULL) + if (res_path != NULL) break; } - return pathName; + return res_path; } /* diff --git a/sntp/libopts/compat/strchr.c b/sntp/libopts/compat/strchr.c index 0def700f8..f40938707 100644 --- a/sntp/libopts/compat/strchr.c +++ b/sntp/libopts/compat/strchr.c @@ -34,7 +34,7 @@ static char * strchr(char const *s, int c) { do { - if ((unsigned)*s == (unsigned)c) + if ((unsigned char)*s == (unsigned char)c) return s; } while (*(++s) != NUL); @@ -51,7 +51,7 @@ strrchr(char const *s, int c) if (--e < s) break; - if ((unsigned)*e == (unsigned)c) + if ((unsigned char)*e == (unsigned char)c) return e; } return NULL; diff --git a/sntp/libopts/configfile.c b/sntp/libopts/configfile.c index 8c71111c5..d96d71cd7 100644 --- a/sntp/libopts/configfile.c +++ b/sntp/libopts/configfile.c @@ -415,12 +415,18 @@ file_preset(tOptions * opts, char const * fname, int dir) tmap_info_t cfgfile; tOptState optst = OPTSTATE_INITIALIZER(PRESET); opt_state_mask_t st_flags = optst.flags; + opt_state_mask_t fl_save = opts->fOptSet; char * ftext = text_mmap(fname, PROT_READ|PROT_WRITE, MAP_PRIVATE, &cfgfile); if (TEXT_MMAP_FAILED_ADDR(ftext)) return; + /* + * While processing config files, we ignore errors. + */ + opts->fOptSet &= ~OPTPROC_ERRSTOP; + if (dir == DIRECTION_CALLED) { st_flags = OPTST_DEFINED; dir = DIRECTION_PROCESS; @@ -483,6 +489,7 @@ file_preset(tOptions * opts, char const * fname, int dir) all_done: text_munmap(&cfgfile); + opts->fOptSet = fl_save; } /** @@ -519,7 +526,7 @@ handle_cfg(tOptions * opts, tOptState * ost, char * txt, int dir) if (txt > pzEnd) { name_only: *pzEnd++ = NUL; - loadOptionLine(opts, ost, pzName, dir, OPTION_LOAD_UNCOOKED); + load_opt_line(opts, ost, pzName, dir, OPTION_LOAD_UNCOOKED); return pzEnd; } @@ -575,7 +582,7 @@ handle_cfg(tOptions * opts, tOptState * ost, char * txt, int dir) * "pzName" points to what looks like text for one option/configurable. * It is NUL terminated. Process it. */ - loadOptionLine(opts, ost, pzName, dir, OPTION_LOAD_UNCOOKED); + load_opt_line(opts, ost, pzName, dir, OPTION_LOAD_UNCOOKED); return pzEnd; } @@ -939,7 +946,7 @@ handle_struct(tOptions * opts, tOptState * ost, char * txt, int dir) return NULL; *txt = NUL; txt += 2; - loadOptionLine(opts, ost, pzName, dir, mode); + load_opt_line(opts, ost, pzName, dir, mode); return txt; case '>': @@ -963,7 +970,7 @@ handle_struct(tOptions * opts, tOptState * ost, char * txt, int dir) return txt; /* - * Rejoin the name and value for parsing by "loadOptionLine()". + * Rejoin the name and value for parsing by "load_opt_line()". * Erase any attributes parsed by "parse_attrs()". */ memset(pcNulPoint, ' ', (size_t)(pzData - pcNulPoint)); @@ -980,7 +987,7 @@ handle_struct(tOptions * opts, tOptState * ost, char * txt, int dir) * "pzName" points to what looks like text for one option/configurable. * It is NUL terminated. Process it. */ - loadOptionLine(opts, ost, pzName, dir, mode); + load_opt_line(opts, ost, pzName, dir, mode); return txt; } diff --git a/sntp/libopts/find.c b/sntp/libopts/find.c index 92584d8f3..1ba504ebc 100644 --- a/sntp/libopts/find.c +++ b/sntp/libopts/find.c @@ -107,6 +107,9 @@ opt_ambiguities(tOptions * opts, char const * name, int nm_len) fputs(zambig_list_msg, stderr); do { + if (pOD->pz_Name == NULL) + continue; /* doc option */ + if (strneqvcmp(name, pOD->pz_Name, nm_len) == 0) fprintf(stderr, zambig_file, hyph, pOD->pz_Name); @@ -375,7 +378,10 @@ opt_find_long(tOptions * opts, char const * opt_name, tOptState * state) bool disable = false; int ct; - if (nm_len <= 0) { + if (nm_len <= 1) { + if ((opts->fOptSet & OPTPROC_ERRSTOP) == 0) + return FAILURE; + fprintf(stderr, zInvalOptName, opts->pzProgName, opt_name); (*opts->pUsageProc)(opts, EXIT_FAILURE); /* NOTREACHED */ @@ -418,6 +424,9 @@ opt_find_short(tOptions* pOpts, uint_t optValue, tOptState* pOptState) if (SKIP_OPT(pRes)) { if ( (pRes->fOptState == (OPTST_OMITTED | OPTST_NO_INIT)) && (pRes->pz_Name != NULL)) { + if ((pOpts->fOptSet & OPTPROC_ERRSTOP) == 0) + return FAILURE; + fprintf(stderr, zDisabledErr, pOpts->pzProgPath, pRes->pz_Name); if (pRes->pzText != NULL) fprintf(stderr, SET_OFF_FMT, pRes->pzText); diff --git a/sntp/libopts/genshell.c b/sntp/libopts/genshell.c index 394f8fec0..1b6625782 100644 --- a/sntp/libopts/genshell.c +++ b/sntp/libopts/genshell.c @@ -2,11 +2,11 @@ * * DO NOT EDIT THIS FILE (genshell.c) * - * It has been AutoGen-ed July 5, 2013 at 08:32:39 PM by AutoGen 5.17.5pre9 + * It has been AutoGen-ed July 28, 2013 at 08:25:19 AM by AutoGen 5.18.1pre2 * From the definitions genshell.def * and the template file options * - * Generated from AutoOpts 39:0:14 templates. + * Generated from AutoOpts 40:1:15 templates. * * AutoOpts is a copyrighted work. This source file is not encumbered * by AutoOpts licensing, but is provided under the licensing terms chosen @@ -476,10 +476,10 @@ translate_option_strings(void) static void bogus_function(void) { /* TRANSLATORS: - The following dummy function was crated solely so that xgettext can extract - the correct strings. These strings are actually referenced by a field name - in the genshelloptOptions structure noted in the comments below. The - literal text is defined in genshellopt_opt_strs. + The following dummy function was crated solely so that xgettext can + extract the correct strings. These strings are actually referenced + by a field name in the genshelloptOptions structure noted in the + comments below. The literal text is defined in genshellopt_opt_strs. NOTE: the strings below are segmented with respect to the source string genshellopt_opt_strs. The strings above are handed off for translation @@ -548,9 +548,9 @@ by the newly generated text. The first '#!' line will be regenerated.\n")); /* referenced via genshelloptOptions.pzShortUsage */ puts(_("<<>>")); /* LIBOPTS-MESSAGES: */ -#line 45 "../autoopts.c" +#line 67 "../autoopts.c" puts(_("allocation of %d bytes failed\n")); -#line 71 "../autoopts.c" +#line 93 "../autoopts.c" puts(_("allocation of %d bytes failed\n")); #line 53 "../init.c" puts(_("AutoOpts function called without option descriptor\n")); @@ -559,7 +559,7 @@ by the newly generated text. The first '#!' line will be regenerated.\n")); #line 88 "../init.c" puts(_("Automated Options Processing Error!\n" "\t%s called AutoOpts function with structure version %d:%d:%d.\n")); -#line 58 "../autoopts.c" +#line 80 "../autoopts.c" puts(_("realloc of %d bytes at 0x%p failed\n")); #line 92 "../init.c" puts(_("\tThis is less than the minimum library version: ")); @@ -576,7 +576,7 @@ by the newly generated text. The first '#!' line will be regenerated.\n")); puts(_("optionProcess() was called with invalid data")); #line 747 "../usage.c" puts(_("invalid argument type specified")); -#line 589 "../find.c" +#line 598 "../find.c" puts(_("defaulted to option with optional arg")); #line 76 "../alias.c" puts(_("aliasing option is out of range.")); @@ -584,7 +584,7 @@ by the newly generated text. The first '#!' line will be regenerated.\n")); puts(_("%s error: the keyword '%s' is ambiguous for %s\n")); #line 108 "../find.c" puts(_(" The following options match:\n")); -#line 290 "../find.c" +#line 293 "../find.c" puts(_("%s: ambiguous option name: %s (matches %d options)\n")); #line 161 "../check.c" puts(_("%s: Command line arguments required\n")); @@ -601,23 +601,23 @@ by the newly generated text. The first '#!' line will be regenerated.\n")); "\t'n' - version and full copyright notice\n")); #line 58 "../check.c" puts(_("%s error: the '%s' and '%s' options conflict\n")); -#line 214 "../find.c" +#line 217 "../find.c" puts(_("%s: The '%s' option has been disabled.")); -#line 421 "../find.c" +#line 430 "../find.c" puts(_("%s: The '%s' option has been disabled.")); #line 38 "../alias.c" puts(_("-equivalence")); -#line 460 "../find.c" +#line 469 "../find.c" puts(_("%s: illegal option -- %c\n")); #line 110 "../reset.c" puts(_("%s: illegal option -- %c\n")); -#line 268 "../find.c" +#line 271 "../find.c" puts(_("%s: illegal option -- %s\n")); -#line 746 "../find.c" +#line 755 "../find.c" puts(_("%s: illegal option -- %s\n")); #line 118 "../reset.c" puts(_("%s: illegal option -- %s\n")); -#line 332 "../find.c" +#line 335 "../find.c" puts(_("%s: unknown vendor extension option -- %s\n")); #line 159 "../enum.c" puts(_(" or an integer from %d through %d\n")); @@ -627,16 +627,16 @@ by the newly generated text. The first '#!' line will be regenerated.\n")); puts(_("%s error: invalid option descriptor for %s\n")); #line 1080 "../usage.c" puts(_("%s error: invalid option descriptor for %s\n")); -#line 379 "../find.c" +#line 385 "../find.c" puts(_("%s: invalid option name: %s\n")); -#line 518 "../find.c" +#line 527 "../find.c" puts(_("%s: The '%s' option requires an argument.\n")); #line 156 "../autoopts.c" puts(_("(AutoOpts bug): Equivalenced option '%s' was equivalenced to both\n" "\t'%s' and '%s'.")); #line 94 "../check.c" puts(_("%s error: The %s option is required\n")); -#line 623 "../find.c" +#line 632 "../find.c" puts(_("%s: The '%s' option cannot have an argument.\n")); #line 151 "../check.c" puts(_("%s: Command line arguments are not allowed.\n")); diff --git a/sntp/libopts/genshell.h b/sntp/libopts/genshell.h index a3f7d3352..6bc8ec2d0 100644 --- a/sntp/libopts/genshell.h +++ b/sntp/libopts/genshell.h @@ -2,11 +2,11 @@ * * DO NOT EDIT THIS FILE (genshell.h) * - * It has been AutoGen-ed July 5, 2013 at 08:32:39 PM by AutoGen 5.17.5pre9 + * It has been AutoGen-ed July 28, 2013 at 08:25:19 AM by AutoGen 5.18.1pre2 * From the definitions genshell.def * and the template file options * - * Generated from AutoOpts 39:0:14 templates. + * Generated from AutoOpts 40:1:15 templates. * * AutoOpts is a copyrighted work. This header file is not encumbered * by AutoOpts licensing, but is provided under the licensing terms chosen @@ -55,7 +55,7 @@ * tolerable version is at least as old as what was current when the header * template was released. */ -#define AO_TEMPLATE_VERSION 159744 +#define AO_TEMPLATE_VERSION 163841 #if (AO_TEMPLATE_VERSION < OPTIONS_MINIMUM_VERSION) \ || (AO_TEMPLATE_VERSION > OPTIONS_STRUCT_VERSION) # error option template version mismatches autoopts/options.h header diff --git a/sntp/libopts/init.c b/sntp/libopts/init.c index 9025887d6..f41d737e4 100644 --- a/sntp/libopts/init.c +++ b/sntp/libopts/init.c @@ -104,14 +104,14 @@ validate_struct(tOptions * opts, char const * pname) char const ** pp = (char const **)(void **)&(opts->pzProgName); - if (pz != NULL) { + if (pz != NULL) *pp = pz+1; - } else { + else *pp = pname; - pz = pathfind(getenv("PATH"), (char *)pname, "rx"); - if (pz != NULL) - pname = (void *)pz; - } + + pz = pathfind(getenv("PATH"), (char *)pname, "rx"); + if (pz != NULL) + pname = (void *)pz; pp = (char const **)(void **)&(opts->pzProgPath); *pp = pname; diff --git a/sntp/libopts/load.c b/sntp/libopts/load.c index 6bc91a430..71e57ecb0 100644 --- a/sntp/libopts/load.c +++ b/sntp/libopts/load.c @@ -33,8 +33,10 @@ /* = = = START-STATIC-FORWARD = = = */ static bool -add_prog_path(char * pzBuf, int b_sz, char const * pzName, - char const * pzProgPath); +get_realpath(char * buf, size_t b_sz); + +static bool +add_prog_path(char * buf, int b_sz, char const * fname, char const * prg_path); static bool add_env_val(char * buf, int buf_sz, char const * name); @@ -44,16 +46,58 @@ assemble_arg_val(char * txt, tOptionLoadMode mode); static char * trim_quotes(char * arg); + +static bool +direction_ok(opt_state_mask_t f, int dir); /* = = = END-STATIC-FORWARD = = = */ +static bool +get_realpath(char * buf, size_t b_sz) +{ +#if defined(HAVE_CANONICALIZE_FILE_NAME) + { + size_t name_len; + + char * pz = canonicalize_file_name(buf); + if (pz == NULL) + return false; + + name_len = strlen(pz); + if (name_len >= (size_t)b_sz) { + free(pz); + return false; + } + + memcpy(buf, pz, name_len + 1); + free(pz); + } + +#elif defined(HAVE_REALPATH) + { + size_t name_len; + char z[PATH_MAX+1]; + + if (realpath(buf, z) == NULL) + return false; + + name_len = strlen(z); + if (name_len >= b_sz) + return false; + + memcpy(buf, z, name_len + 1); + } +#endif + return true; +} + /*=export_func optionMakePath * private: * * what: translate and construct a path - * arg: + char* + pzBuf + The result buffer + - * arg: + int + bufSize + The size of this buffer + - * arg: + char const* + pzName + The input name + - * arg: + char const* + pzProgPath + The full path of the current program + + * arg: + char* + p_buf + The result buffer + + * arg: + int + b_sz + The size of this buffer + + * arg: + char const* + fname + The input name + + * arg: + char const* + prg_path + The full path of the current program + * * ret-type: bool * ret-desc: true if the name was handled, otherwise false. @@ -98,24 +142,25 @@ trim_quotes(char * arg); * errors (cannot resolve the resulting path). =*/ bool -optionMakePath(char * pzBuf, int b_sz, char const * pzName, - char const * pzProgPath) +optionMakePath(char * p_buf, int b_sz, char const * fname, char const * prg_path) { - size_t name_len = strlen(pzName); + { + size_t len = strlen(fname); - if (((size_t)b_sz <= name_len) || (name_len == 0)) - return false; + if (((size_t)b_sz <= len) || (len == 0)) + return false; + } /* * IF not an environment variable, just copy the data */ - if (*pzName != '$') { - char const* pzS = pzName; - char* pzD = pzBuf; - int ct = b_sz; + if (*fname != '$') { + char const * src = fname; + char * dst = p_buf; + int ct = b_sz; for (;;) { - if ( (*(pzD++) = *(pzS++)) == NUL) + if ( (*(dst++) = *(src++)) == NUL) break; if (--ct <= 0) return false; @@ -127,12 +172,12 @@ optionMakePath(char * pzBuf, int b_sz, char const * pzName, * it must start with "$$/". In either event, replace the "$$" * with the path to the executable and append a "/" character. */ - else switch (pzName[1]) { + else switch (fname[1]) { case NUL: return false; case '$': - if (! add_prog_path(pzBuf, b_sz, pzName, pzProgPath)) + if (! add_prog_path(p_buf, b_sz, fname, prg_path)) return false; break; @@ -140,59 +185,30 @@ optionMakePath(char * pzBuf, int b_sz, char const * pzName, if (program_pkgdatadir[0] == NUL) return false; - if (snprintf(pzBuf, (size_t)b_sz, "%s%s", - program_pkgdatadir, pzName + 2) >= b_sz) + if (snprintf(p_buf, (size_t)b_sz, "%s%s", + program_pkgdatadir, fname + 2) >= b_sz) return false; break; default: - if (! add_env_val(pzBuf, b_sz, pzName)) - return false; - } - -#if defined(HAVE_CANONICALIZE_FILE_NAME) - { - char * pz = canonicalize_file_name(pzBuf); - if (pz == NULL) + if (! add_env_val(p_buf, b_sz, fname)) return false; - - name_len = strlen(pz); - if (name_len >= (size_t)b_sz) { - free(pz); - return false; - } - - memcpy(pzBuf, pz, name_len + 1); - free(pz); } -#elif defined(HAVE_REALPATH) - { - char z[PATH_MAX+1]; - - if (realpath(pzBuf, z) == NULL) - return false; - - name_len = strlen(z); - if (name_len >= b_sz) - return false; - - memcpy(pzBuf, z, name_len + 1); - } -#endif - - return true; + return get_realpath(p_buf, b_sz); } +/** + * convert a leading "$$" into a path to the executable. + */ static bool -add_prog_path(char * pzBuf, int b_sz, char const * pzName, - char const * pzProgPath) +add_prog_path(char * buf, int b_sz, char const * fname, char const * prg_path) { - char const* pzPath; - char const* pz; + char const * path; + char const * pz; int skip = 2; - switch (pzName[2]) { + switch (fname[2]) { case DIRCH: skip = 3; case NUL: @@ -206,16 +222,16 @@ add_prog_path(char * pzBuf, int b_sz, char const * pzName, * If it is, we're done. Otherwise, we have to hunt * for the program using "pathfind". */ - if (strchr(pzProgPath, DIRCH) != NULL) - pzPath = pzProgPath; + if (strchr(prg_path, DIRCH) != NULL) + path = prg_path; else { - pzPath = pathfind(getenv("PATH"), (char*)pzProgPath, "rx"); + path = pathfind(getenv("PATH"), (char*)prg_path, "rx"); - if (pzPath == NULL) + if (path == NULL) return false; } - pz = strrchr(pzPath, DIRCH); + pz = strrchr(path, DIRCH); /* * IF we cannot find a directory name separator, @@ -224,27 +240,30 @@ add_prog_path(char * pzBuf, int b_sz, char const * pzName, if (pz == NULL) return false; - pzName += skip; + fname += skip; /* * Concatenate the file name to the end of the executable path. * The result may be either a file or a directory. */ - if ((unsigned)(pz - pzPath) + 1 + strlen(pzName) >= (unsigned)b_sz) + if ((unsigned)(pz - path) + 1 + strlen(fname) >= (unsigned)b_sz) return false; - memcpy(pzBuf, pzPath, (size_t)((pz - pzPath)+1)); - strcpy(pzBuf + (pz - pzPath) + 1, pzName); + memcpy(buf, path, (size_t)((pz - path)+1)); + strcpy(buf + (pz - path) + 1, fname); /* - * If the "pzPath" path was gotten from "pathfind()", then it was + * If the "path" path was gotten from "pathfind()", then it was * allocated and we need to deallocate it. */ - if (pzPath != pzProgPath) - AGFREE(pzPath); + if (path != prg_path) + AGFREE(path); return true; } +/** + * Add an environment variable value. + */ static bool add_env_val(char * buf, int buf_sz, char const * name) { @@ -294,9 +313,9 @@ munge_str(char * txt, tOptionLoadMode mode) return; if (IS_WHITESPACE_CHAR(*txt)) { - char * pzS = SPN_WHITESPACE_CHARS(txt+1); - size_t l = strlen(pzS) + 1; - memmove(txt, pzS, l); + char * src = SPN_WHITESPACE_CHARS(txt+1); + size_t l = strlen(src) + 1; + memmove(txt, src, l); pzE = txt + l - 1; } else @@ -372,83 +391,63 @@ trim_quotes(char * arg) } /** - * Load an option from a block of text. The text must start with the - * configurable/option name and be followed by its associated value. - * That value may be processed in any of several ways. See "tOptionLoadMode" - * in autoopts.h. - * - * @param[in,out] opts program options descriptor - * @param[in,out] opt_state option processing state - * @param[in,out] line source line with long option name in it - * @param[in] direction current processing direction (preset or not) - * @param[in] load_mode option loading mode (OPTION_LOAD_*) + * See if the option is to be processed in the current scan direction + * (-1 or +1). */ -LOCAL void -loadOptionLine(tOptions * opts, tOptState * opt_state, char * line, - tDirection direction, tOptionLoadMode load_mode ) +static bool +direction_ok(opt_state_mask_t f, int dir) { - line = SPN_LOAD_LINE_SKIP_CHARS(line); - - { - char * arg = assemble_arg_val(line, load_mode); - - if (! SUCCESSFUL(opt_find_long(opts, line, opt_state))) - return; - - if (opt_state->flags & OPTST_NO_INIT) - return; + if (dir == 0) + return true; - opt_state->pzOptArg = trim_quotes(arg); - } - - switch (opt_state->flags & (OPTST_IMM|OPTST_DISABLE_IMM)) { + switch (f & (OPTST_IMM|OPTST_DISABLE_IMM)) { case 0: /* * The selected option has no immediate action. * THEREFORE, if the direction is PRESETTING * THEN we skip this option. */ - if (PRESETTING(direction)) - return; + if (PRESETTING(dir)) + return false; break; case OPTST_IMM: - if (PRESETTING(direction)) { + if (PRESETTING(dir)) { /* * We are in the presetting direction with an option we handle * immediately for enablement, but normally for disablement. * Therefore, skip if disabled. */ - if ((opt_state->flags & OPTST_DISABLED) == 0) - return; + if ((f & OPTST_DISABLED) == 0) + return false; } else { /* * We are in the processing direction with an option we handle * immediately for enablement, but normally for disablement. * Therefore, skip if NOT disabled. */ - if ((opt_state->flags & OPTST_DISABLED) != 0) - return; + if ((f & OPTST_DISABLED) != 0) + return false; } break; case OPTST_DISABLE_IMM: - if (PRESETTING(direction)) { + if (PRESETTING(dir)) { /* * We are in the presetting direction with an option we handle * immediately for disablement, but normally for disablement. * Therefore, skip if NOT disabled. */ - if ((opt_state->flags & OPTST_DISABLED) != 0) - return; + if ((f & OPTST_DISABLED) != 0) + return false; } else { /* * We are in the processing direction with an option we handle * immediately for disablement, but normally for disablement. * Therefore, skip if disabled. */ - if ((opt_state->flags & OPTST_DISABLED) == 0) - return; + if ((f & OPTST_DISABLED) == 0) + return false; } break; @@ -458,10 +457,55 @@ loadOptionLine(tOptions * opts, tOptState * opt_state, char * line, * THEREFORE, if the direction is PROCESSING * THEN we skip this option. */ - if (PROCESSING(direction)) - return; + if (PROCESSING(dir)) + return false; break; } + return true; +} + +/** + * Load an option from a block of text. The text must start with the + * configurable/option name and be followed by its associated value. + * That value may be processed in any of several ways. See "tOptionLoadMode" + * in autoopts.h. + * + * @param[in,out] opts program options descriptor + * @param[in,out] opt_state option processing state + * @param[in,out] line source line with long option name in it + * @param[in] direction current processing direction (preset or not) + * @param[in] load_mode option loading mode (OPTION_LOAD_*) + */ +LOCAL void +load_opt_line(tOptions * opts, tOptState * opt_state, char * line, + tDirection direction, tOptionLoadMode load_mode ) +{ + /* + * When parsing a stored line, we only look at the characters after + * a hyphen. Long names must always be at least two characters and + * short options are always exactly one character long. + */ + line = SPN_LOAD_LINE_SKIP_CHARS(line); + + { + char * arg = assemble_arg_val(line, load_mode); + + if (IS_OPTION_NAME_CHAR(line[1])) { + + if (! SUCCESSFUL(opt_find_long(opts, line, opt_state))) + return; + + } else if (! SUCCESSFUL(opt_find_short(opts, *line, opt_state))) + return; + + if ((! CALLED(direction)) && (opt_state->flags & OPTST_NO_INIT)) + return; + + opt_state->pzOptArg = trim_quotes(arg); + } + + if (! direction_ok(opt_state->flags, direction)) + return; /* * Fix up the args. @@ -526,10 +570,13 @@ void optionLoadLine(tOptions * opts, char const * line) { tOptState st = OPTSTATE_INITIALIZER(SET); - char* pz; - AGDUPSTR(pz, line, "user option line"); - loadOptionLine(opts, &st, pz, DIRECTION_PROCESS, OPTION_LOAD_COOKED); + char * pz; + proc_state_mask_t sv_flags = opts->fOptSet; + opts->fOptSet &= ~OPTPROC_ERRSTOP; + AGDUPSTR(pz, line, "opt line"); + load_opt_line(opts, &st, pz, DIRECTION_CALLED, OPTION_LOAD_COOKED); AGFREE(pz); + opts->fOptSet = sv_flags; } /** @} * diff --git a/sntp/libopts/m4/libopts.m4 b/sntp/libopts/m4/libopts.m4 index 3afa17456..a651c3ff0 100644 --- a/sntp/libopts/m4/libopts.m4 +++ b/sntp/libopts/m4/libopts.m4 @@ -2,7 +2,7 @@ dnl -*- buffer-read-only: t -*- vi: set ro: dnl dnl DO NOT EDIT THIS FILE (libopts.m4) dnl -dnl It has been AutoGen-ed July 5, 2013 at 08:32:31 PM by AutoGen 5.17.5pre9 +dnl It has been AutoGen-ed July 28, 2013 at 08:25:12 AM by AutoGen 5.18.1pre2 dnl From the definitions libopts.def dnl and the template file conftest.tpl dnl diff --git a/sntp/libopts/option-value-type.c b/sntp/libopts/option-value-type.c index f0ceba68a..a89ed691e 100644 --- a/sntp/libopts/option-value-type.c +++ b/sntp/libopts/option-value-type.c @@ -2,7 +2,7 @@ * * DO NOT EDIT THIS FILE (stdin.c) * - * It has been AutoGen-ed July 5, 2013 at 08:32:38 PM by AutoGen 5.17.5pre9 + * It has been AutoGen-ed July 28, 2013 at 08:25:18 AM by AutoGen 5.18.1pre2 * From the definitions stdin * and the template file str2enum * diff --git a/sntp/libopts/option-value-type.h b/sntp/libopts/option-value-type.h index e1a1758d2..501e6ac0b 100644 --- a/sntp/libopts/option-value-type.h +++ b/sntp/libopts/option-value-type.h @@ -2,7 +2,7 @@ * * DO NOT EDIT THIS FILE (stdin.h) * - * It has been AutoGen-ed July 5, 2013 at 08:32:37 PM by AutoGen 5.17.5pre9 + * It has been AutoGen-ed July 28, 2013 at 08:25:18 AM by AutoGen 5.18.1pre2 * From the definitions stdin * and the template file str2enum * diff --git a/sntp/libopts/option-xat-attribute.c b/sntp/libopts/option-xat-attribute.c index 0ee1668c5..db31def94 100644 --- a/sntp/libopts/option-xat-attribute.c +++ b/sntp/libopts/option-xat-attribute.c @@ -2,7 +2,7 @@ * * DO NOT EDIT THIS FILE (stdin.c) * - * It has been AutoGen-ed July 5, 2013 at 08:32:36 PM by AutoGen 5.17.5pre9 + * It has been AutoGen-ed July 28, 2013 at 08:25:17 AM by AutoGen 5.18.1pre2 * From the definitions stdin * and the template file str2enum * diff --git a/sntp/libopts/option-xat-attribute.h b/sntp/libopts/option-xat-attribute.h index b6ce13949..2da4d4e10 100644 --- a/sntp/libopts/option-xat-attribute.h +++ b/sntp/libopts/option-xat-attribute.h @@ -2,7 +2,7 @@ * * DO NOT EDIT THIS FILE (stdin.h) * - * It has been AutoGen-ed July 5, 2013 at 08:32:36 PM by AutoGen 5.17.5pre9 + * It has been AutoGen-ed July 28, 2013 at 08:25:17 AM by AutoGen 5.18.1pre2 * From the definitions stdin * and the template file str2enum * diff --git a/sntp/libopts/pgusage.c b/sntp/libopts/pgusage.c index 515441023..18a00100e 100644 --- a/sntp/libopts/pgusage.c +++ b/sntp/libopts/pgusage.c @@ -50,7 +50,11 @@ open_tmp_usage(char ** buf) } { + static mode_t const cmask = S_IRWXO | S_IRWXG; + mode_t svmsk = umask(cmask); int fd = mkstemp(bf); + (void)umask(svmsk); + if (fd < 0) { AGFREE(bf); return NULL; diff --git a/sntp/libopts/proto.h b/sntp/libopts/proto.h index 5730fca43..5f65ec9ad 100644 --- a/sntp/libopts/proto.h +++ b/sntp/libopts/proto.h @@ -1,7 +1,7 @@ /* -*- buffer-read-only: t -*- vi: set ro: * * Prototypes for autoopts - * Generated Fri Jul 5 20:32:50 PDT 2013 + * Generated Sun Jul 28 08:25:30 PDT 2013 */ #ifndef AUTOOPTS_PROTO_H_GUARD #define AUTOOPTS_PROTO_H_GUARD 1 @@ -92,8 +92,8 @@ static void munge_str(char * txt, tOptionLoadMode mode); static void -loadOptionLine(tOptions * opts, tOptState * opt_state, char * line, - tDirection direction, tOptionLoadMode load_mode ); +load_opt_line(tOptions * opts, tOptState * opt_state, char * line, + tDirection direction, tOptionLoadMode load_mode ); /* * Extracted from makeshell.c diff --git a/sntp/libopts/streqvcmp.c b/sntp/libopts/streqvcmp.c index 8fae58fac..08cb63710 100644 --- a/sntp/libopts/streqvcmp.c +++ b/sntp/libopts/streqvcmp.c @@ -243,7 +243,7 @@ strequate(char const* s) if ((s != NULL) && (*s != NUL)) { unsigned char equiv = (unsigned char)*s; while (*s != NUL) - charmap[ (unsigned)*(s++) ] = equiv; + charmap[(unsigned char)*(s++)] = equiv; } } @@ -270,7 +270,7 @@ void strtransform(char* d, char const* s) { do { - *(d++) = (char)charmap[ (unsigned)*s ]; + *(d++) = (char)charmap[(unsigned char)*s]; } while (*(s++) != NUL); } diff --git a/sntp/libopts/text_mmap.c b/sntp/libopts/text_mmap.c index 7085f3eb0..fac0c6414 100644 --- a/sntp/libopts/text_mmap.c +++ b/sntp/libopts/text_mmap.c @@ -175,24 +175,6 @@ validate_mmap(char const * fname, int prot, int flags, tmap_info_t * mapinfo) mapinfo->txt_prot = prot; mapinfo->txt_flags = flags; - /* - * Make sure we can stat the regular file. Save the file size. - */ - { - struct stat sb; - if (stat(fname, &sb) != 0) { - mapinfo->txt_errno = errno; - return; - } - - if (! S_ISREG(sb.st_mode)) { - mapinfo->txt_errno = errno = EINVAL; - return; - } - - mapinfo->txt_size = (size_t)sb.st_size; - } - /* * Map mmap flags and protections into open flags and do the open. */ @@ -213,6 +195,31 @@ validate_mmap(char const * fname, int prot, int flags, tmap_info_t * mapinfo) o_flag |= O_EXCL; mapinfo->txt_fd = open(fname, o_flag); + if (mapinfo->txt_fd < 0) { + mapinfo->txt_errno = errno; + mapinfo->txt_fd = AO_INVALID_FD; + return; + } + } + + /* + * Make sure we can stat the regular file. Save the file size. + */ + { + struct stat sb; + if (fstat(mapinfo->txt_fd, &sb) != 0) { + mapinfo->txt_errno = errno; + close(mapinfo->txt_fd); + return; + } + + if (! S_ISREG(sb.st_mode)) { + mapinfo->txt_errno = errno = EINVAL; + close(mapinfo->txt_fd); + return; + } + + mapinfo->txt_size = (size_t)sb.st_size; } if (mapinfo->txt_fd == AO_INVALID_FD) diff --git a/sntp/libopts/usage.c b/sntp/libopts/usage.c index da77c61b9..c7c9cd0f1 100644 --- a/sntp/libopts/usage.c +++ b/sntp/libopts/usage.c @@ -319,6 +319,7 @@ print_offer_usage(tOptions * opts) case OPTPROC_LONGOPT: case (OPTPROC_LONGOPT | OPTPROC_SHORTOPT): strcpy(help, "--help"); + break; case 0: strcpy(help, "help");