switch the "namespace" to "lce" master
authorgit <redacted>
Fri, 17 Jul 2026 19:52:00 +0000 (15:52 -0400)
committergit <redacted>
Fri, 17 Jul 2026 19:52:00 +0000 (15:52 -0400)
getopt_long.h: define HAVE_GETOPT if not already defined

README.md
asprintf.h
fgetln.h
getopt_long.h
strdup.h
strlcat.h
strtonum.h

index 8324035f51400315c5fa93d0fd44fadc2e8a7d93..e9373ec148bad174de9ad7184505b45adbb0d39b 100644 (file)
--- a/README.md
+++ b/README.md
@@ -7,26 +7,26 @@ All functions are implemented as macros expanding to an internal function refere
 Include the header in every file needed as usual:
 
 ```
-#include "<ext-func-name>.h"
+#include "${function}.h"
 ```
 
 In the file chosen for the function implementation:
 
 ```
-#define <EXT-FUNC-NAME>_IMPLEMENTATION
-#include "<ext-func-name.h>"
+#define LCE_${FUNCTION}_IMPLEMENTATION
+#include "${function}.h>"
 ```
 
 By default, the header won't have any stdlib includes, change that with:
 
 ```
-#define <EXT-FUNC-NAME>_INCLUDE_LIBC
+#define LCE_${FUNCTION}_INCLUDE_LIBC
 ```
 
 Or disable function, type and variable override with:
 
 ```
-#define HAVE_<EXT-FUNC-NAME>
+#define HAVE_${FUNCTION}
 ```
 
 ### Specifics
@@ -53,9 +53,9 @@ includes `getopt()`, `getsubopt()`, `getopt_long()` and `getopt_long_only()`
 permuting, defining those enables it per function (GNU behaviour, can still be disabled at runtime by setting `$POSIXLY_CORRECT`):
 
 ```
-#define GETOPT_PERMUTE_ARGS
-#define GETOPT_LONG_PERMUTE_ARGS
-#define GETOPT_LONG_ONLY_PERMUTE_ARGS
+#define LCE_GETOPT_PERMUTE_ARGS
+#define LCE_GETOPT_LONG_PERMUTE_ARGS
+#define LCE_GETOPT_LONG_ONLY_PERMUTE_ARGS
 ```
 
 ---
index ddce911bff42210a5b1888d286c0846643783e59..47b97520e1ee57be64bbb0d6f8383c1bc1b16676 100644 (file)
  */
 
 /* https://git.datadissipation.net */
-#ifndef ASPRINTF_H_
- #define ASPRINTF_H_            1
+#ifndef LCE_ASPRINTF_H
+ #define LCE_ASPRINTF_H            1
 
- #ifdef ASPRINTF_INCLUDE_LIBC
+ #ifdef LCE_ASPRINTF_INCLUDE_LIBC
   #include <stdarg.h>
   #include <stdio.h>
   #include <stdlib.h>
- #endif /* ASPRINTF_INCLUDE_LIBC */
+ #endif /* LCE_ASPRINTF_INCLUDE_LIBC */
 
  #ifndef HAVE_ASPRINTF
   #define HAVE_ASPRINTF         1
-  #define asprintf              i_asprintf_
-  #define vasprintf             i_vasprintf_
-int i_vasprintf_(char **strp, const char *fmt, va_list ap);
-int i_asprintf_(char **strp, const char *fmt, ...);
+  #define asprintf              lce_asprintf_
+  #define vasprintf             lce_vasprintf_
+int lce_vasprintf_(char **strp, const char *fmt, va_list ap);
+int lce_asprintf_(char **strp, const char *fmt, ...);
  #endif /* !HAVE_ASPRINTF */
 
- #ifdef ASPRINTF_IMPLEMENTATION
+ #ifdef LCE_ASPRINTF_IMPLEMENTATION
 int
-i_vasprintf_(char **strp, const char *fmt, va_list ap)
+lce_vasprintf_(char **strp, const char *fmt, va_list ap)
 {
        int size;
        va_list tp;
@@ -61,16 +61,16 @@ i_vasprintf_(char **strp, const char *fmt, va_list ap)
 }
 
 int
-i_asprintf_(char **strp, const char *fmt, ...)
+lce_asprintf_(char **strp, const char *fmt, ...)
 {
        int ret;
        va_list ap;
 
        va_start(ap, fmt);
-       ret = i_vasprintf_(strp, fmt, ap);
+       ret = lce_vasprintf_(strp, fmt, ap);
        va_end(ap);
 
        return ret;
 }
- #endif /* ASPRINTF_IMPLEMENTATION */
-#endif /* !ASPRINTF_H_ */
+ #endif /* LCE_ASPRINTF_IMPLEMENTATION */
+#endif /* !LCE_ASPRINTF_H */
index 92a0f95d13c0d47d4078f94652a258da1a9c2778..93bd072be2601979e063689d9de6d7ffdbe132f2 100644 (file)
--- a/fgetln.h
+++ b/fgetln.h
  */
 
 /* https://git.datadissipation.net */
-#ifndef FGETLN_H_
- #define FGETLN_H_      1
+#ifndef LCE_FGETLN_H
+ #define LCE_FGETLN_H      1
 
- #ifdef FGETLN_INCLUDE_LIBC
+ #ifdef LCE_FGETLN_INCLUDE_LIBC
   #include <errno.h>
   #include <stdio.h>
   #include <stdlib.h>
   #include <string.h>
   #include <unistd.h>
- #endif /* FGETLN_INCLUDE_LIBC */
+ #endif /* LCE_FGETLN_INCLUDE_LIBC */
 
  #ifndef HAVE_FGETLN
   #define HAVE_FGETLN   1
-  #define fgetln        i_fgetln_
-char *i_fgetln_(FILE *, size_t *);
+  #define fgetln        lce_fgetln_
+char *lce_fgetln_(FILE *, size_t *);
  #endif /* !HAVE_FGETLN */
 
- #ifdef FGETLN_IMPLEMENTATION
+ #ifdef LCE_FGETLN_IMPLEMENTATION
 char *
-i_fgetln_(FILE *fp, size_t *len)
+lce_fgetln_(FILE *fp, size_t *len)
 {
        static char *buf = NULL;
        static size_t bufsiz = 0;
@@ -90,5 +90,5 @@ i_fgetln_(FILE *fp, size_t *len)
        *len = (ptr - buf) + 1;
        return buf;
 }
- #endif /* FGETLN_IMPLEMENTATION */
-#endif /* !FGETLN_H_ */
+ #endif /* LCE_FGETLN_IMPLEMENTATION */
+#endif /* !LCE_FGETLN_H */
index 3878fabc918db24f33e82a6333b83e171a7eb3a9..06fac1cbed65919c94da8051c2bdd9bfa5a1bb89 100644 (file)
  */
 
 /* https://git.datadissipation.net */
-#ifndef GETOPT_LONG_H_
- #define GETOPT_LONG_H_         1
+#ifndef LCE_GETOPT_LONG_H
+ #define LCE_GETOPT_LONG_H         1
 
- #ifdef GETOPT_LONG_INCLUDE_LIBC
+ #ifdef LCE_GETOPT_LONG_INCLUDE_LIBC
   #include <stdarg.h>
   #include <stdio.h>
   #include <stdlib.h>
   #include <string.h>
- #endif /* GETOPT_LONG_INCLUDE_LIBC */
+ #endif /* LCE_GETOPT_LONG_INCLUDE_LIBC */
 
  #ifndef HAVE_GETOPT_LONG
   #define HAVE_GETOPT_LONG      1
+  #ifndef HAVE_GETOPT
+   #define HAVE_GETOPT          1
+  #endif /* !HAVE_GETOPT */
 
   #define no_argument           0
   #define required_argument     1
  * structs are in their own namespace, so this should be OK
  * the worst it can do is make compiler messages worse
  */
-  #define option                i_option_
-
-  #define optarg                i_optarg_
-  #define suboptarg             i_suboptarg_
-  #define optind                i_optind_
-  #define opterr                i_opterr_
-  #define optopt                i_optopt_
-  #define optreset              i_optreset_
-
-  #define getopt                i_getopt_
-  #define getsubopt             i_getsubopt_
-  #define getopt_long           i_getopt_long_
-  #define getopt_long_only      i_getopt_long_only_
-
-  #ifndef GETOPT_LONG_IMPLEMENTATION
-extern char *i_optarg_;
-extern char *i_suboptarg_;
-extern int i_optind_, i_opterr_, i_optopt_, i_optreset_;
-  #endif /* !GETOPT_LONG_IMPLEMENTATION */
-
-struct i_option_ {
+  #define option                lce_option_
+
+  #define optarg                lce_optarg_
+  #define suboptarg             lce_suboptarg_
+  #define optind                lce_optind_
+  #define opterr                lce_opterr_
+  #define optopt                lce_optopt_
+  #define optreset              lce_optreset_
+
+  #define getopt                lce_getopt_
+  #define getsubopt             lce_getsubopt_
+  #define getopt_long           lce_getopt_long_
+  #define getopt_long_only      lce_getopt_long_only_
+
+  #ifndef LCE_GETOPT_LONG_IMPLEMENTATION
+extern char *lce_optarg_;
+extern char *lce_suboptarg_;
+extern int lce_optind_, lce_opterr_, lce_optopt_, lce_optreset_;
+  #endif /* !LCE_GETOPT_LONG_IMPLEMENTATION */
+
+struct lce_option_ {
        const char *name;
        /*
         * one of no_argument, required_argument, and optional_argument:
@@ -92,68 +95,68 @@ struct i_option_ {
        int val;
 };
 
-int   i_getopt_(int argc, char * const *argv, const char *optstring);
-int   i_getsubopt_(char **optionp, char * const *tokens, char **valuep);
-int   i_getopt_long_(int argc, char * const *argv, const char *optstring,
+int   lce_getopt_(int argc, char * const *argv, const char *optstring);
+int   lce_getsubopt_(char **optionp, char * const *tokens, char **valuep);
+int   lce_getopt_long_(int argc, char * const *argv, const char *optstring,
                     const struct option *longopts, int *longindex);
-int   i_getopt_long_only_(int argc, char * const *argv, const char *optstring,
+int   lce_getopt_long_only_(int argc, char * const *argv, const char *optstring,
                          const struct option *longopts, int *longindex);
 
  #endif /* !HAVE_GETOPT_LONG */
 
- #ifdef GETOPT_LONG_IMPLEMENTATION
-  #define I_PRINT_ERROR_       ((i_opterr_) && (*options != ':'))
+ #ifdef LCE_GETOPT_LONG_IMPLEMENTATION
+  #define LCE_PRINT_ERROR_     ((lce_opterr_) && (*options != ':'))
 
-  #define I_FLAG_PERMUTE_      0x01    /* permute non-options to the end of argv */
-  #define I_FLAG_ALLARGS_      0x02    /* treat non-options as args to option "-1" */
-  #define I_FLAG_LONGONLY_     0x04    /* operate as getopt_long_only */
+  #define LCE_FLAG_PERMUTE_    0x01    /* permute non-options to the end of argv */
+  #define LCE_FLAG_ALLARGS_    0x02    /* treat non-options as args to option "-1" */
+  #define LCE_FLAG_LONGONLY_   0x04    /* operate as getopt_long_only */
 
 /* return values */
-  #define      I_BADCH_        (int) '?'
-  #define      I_BADARG_       ((*options == ':') ? (int) ':' : (int) '?')
-  #define      I_INORDER_      (int) 1
+  #define      LCE_BADCH_      (int) '?'
+  #define      LCE_BADARG_     ((*options == ':') ? (int) ':' : (int) '?')
+  #define      LCE_INORDER_    (int) 1
 
-  #define      I_EMSG_         ""
+  #define      LCE_EMSG_               ""
 
-int i_opterr_ = 1;                      /* if error message should be printed */
-int i_optind_ = 1;                      /* index into parent argv vector */
-int i_optopt_ = '?';                    /* character checked for validity */
-int i_optreset_;                        /* reset getopt */
-char  *i_optarg_;                       /* argument associated with option */
-char  *i_suboptarg_;                    /* argument associated with suboption */
+int lce_opterr_ = 1;                      /* if error message should be printed */
+int lce_optind_ = 1;                      /* index into parent argv vector */
+int lce_optopt_ = '?';                    /* character checked for validity */
+int lce_optreset_;                        /* reset getopt */
+char  *lce_optarg_;                       /* argument associated with option */
+char  *lce_suboptarg_;                    /* argument associated with suboption */
 
 /* XXX: set optreset to 1 rather than these two */
-static int i_nonopt_start_ = -1;        /* first non option argument (for permute) */
-static int i_nonopt_end_ = -1;          /* first option after non options (for permute) */
-static char   *i_place_ = I_EMSG_;      /* option letter processing */
-static char   *i_progname_;             /* program name == argv[0] */
+static int lce_nonopt_start_ = -1;        /* first non option argument (for permute) */
+static int lce_nonopt_end_ = -1;          /* first option after non options (for permute) */
+static char   *lce_place_ = LCE_EMSG_;      /* option letter processing */
+static char   *lce_progname_;             /* program name == argv[0] */
 
 /* Error messages */
-static const char i_recargchar_[] = "option requires an argument -- %c";
-static const char i_recargstring_[] = "option requires an argument -- %s";
-static const char i_ambig_[] = "i_ambig_uous option -- %.*s";
-static const char i_noarg_[] = "option doesn't take an argument -- %.*s";
-static const char i_illoptchar_[] = "unknown option -- %c";
-static const char i_illoptstring_[] = "unknown option -- %s";
-
-static void i_warnx_(const char *, ...);
-static int  i_getopt_internal_(int, char * const *, const char *,
+static const char lce_recargchar_[] = "option requires an argument -- %c";
+static const char lce_recargstring_[] = "option requires an argument -- %s";
+static const char lce_ambig_[] = "ambiguous option -- %.*s";
+static const char lce_noarg_[] = "option doesn't take an argument -- %.*s";
+static const char lce_illoptchar_[] = "unknown option -- %c";
+static const char lce_illoptstring_[] = "unknown option -- %s";
+
+static void lce_warnx_(const char *, ...);
+static int  lce_getopt_internal_(int, char * const *, const char *,
                               const struct option *, int *, int);
-static int  i_parse_long_options__(char * const *, const char *,
+static int  lce_parse_long_options__(char * const *, const char *,
                                   const struct option *, int *, int);
-static int  i_gcd_(int, int);
-static void i_permute_args_(int, int, int, char * const *);
+static int  lce_gcd_(int, int);
+static void lce_permute_args_(int, int, int, char * const *);
 
 /*
  * Own warnx() for portability
  */
 void
-i_warnx_(const char *fmt, ...)
+lce_warnx_(const char *fmt, ...)
 {
        va_list args;
 
        va_start(args, fmt);
-       fprintf(stderr, "%s: ", i_progname_);
+       fprintf(stderr, "%s: ", lce_progname_);
        vfprintf(stderr, fmt, args);
        fputc('\n', stderr);
        va_end(args);
@@ -163,7 +166,7 @@ i_warnx_(const char *fmt, ...)
  * Compute the greatest common divisor of a and b.
  */
 static int
-i_gcd_(int a, int b)
+lce_gcd_(int a, int b)
 {
        int c;
 
@@ -183,7 +186,7 @@ i_gcd_(int a, int b)
  * in each block).
  */
 static void
-i_permute_args_(int panonopt_start, int panonopt_end, int opt_end,
+lce_permute_args_(int panonopt_start, int panonopt_end, int opt_end,
                char * const *nargv)
 {
        int cstart, cyclelen, i, j, ncycle, nnonopts, nopts, pos;
@@ -194,7 +197,7 @@ i_permute_args_(int panonopt_start, int panonopt_end, int opt_end,
         */
        nnonopts = panonopt_end - panonopt_start;
        nopts = opt_end - panonopt_end;
-       ncycle = i_gcd_(nnonopts, nopts);
+       ncycle = lce_gcd_(nnonopts, nopts);
        cyclelen = (opt_end - panonopt_start) / ncycle;
 
        for (i = 0; i < ncycle; i++) {
@@ -215,12 +218,12 @@ i_permute_args_(int panonopt_start, int panonopt_end, int opt_end,
 }
 
 /*
- * i_parse_long_options__ --
+ * lce_parse_long_options__ --
  *     Parse long options in argc/argv argument vector.
  * Returns -1 if short_too is set and the option does not match long_options.
  */
 static int
-i_parse_long_options__(char * const *nargv, const char *options,
+lce_parse_long_options__(char * const *nargv, const char *options,
                       const struct option *long_options, int *idx, int
                       short_too)
 {
@@ -228,10 +231,10 @@ i_parse_long_options__(char * const *nargv, const char *options,
        size_t current_argv_len;
        int i, match;
 
-       current_argv = i_place_;
+       current_argv = lce_place_;
        match = -1;
 
-       i_optind_++;
+       lce_optind_++;
 
        if ((has_equal = strchr(current_argv, '=')) != NULL) {
                /* argument found (--option=arg) */
@@ -262,68 +265,68 @@ i_parse_long_options__(char * const *nargv, const char *options,
                        match = i;
                } else {
                        /* ambiguous abbreviation */
-                       if (I_PRINT_ERROR_)
-                               i_warnx_(i_ambig_, (int) current_argv_len,
+                       if (LCE_PRINT_ERROR_)
+                               lce_warnx_(lce_ambig_, (int) current_argv_len,
                                         current_argv);
-                       i_optopt_ = 0;
-                       return (I_BADCH_);
+                       lce_optopt_ = 0;
+                       return (LCE_BADCH_);
                }
        }
        if (match != -1) {              /* option found */
                if (long_options[match].has_arg == no_argument
                    && has_equal) {
-                       if (I_PRINT_ERROR_)
-                               i_warnx_(i_noarg_, (int) current_argv_len,
+                       if (LCE_PRINT_ERROR_)
+                               lce_warnx_(lce_noarg_, (int) current_argv_len,
                                         current_argv);
                        /*
                         * XXX: GNU sets optopt to val regardless of flag
                         */
                        if (long_options[match].flag == NULL)
-                               i_optopt_ = long_options[match].val;
+                               lce_optopt_ = long_options[match].val;
                        else
-                               i_optopt_ = 0;
-                       return (I_BADARG_);
+                               lce_optopt_ = 0;
+                       return (LCE_BADARG_);
                }
                if (long_options[match].has_arg == required_argument ||
                    long_options[match].has_arg == optional_argument) {
                        if (has_equal){
-                               i_optarg_ = has_equal;
+                               lce_optarg_ = has_equal;
                        } else if (long_options[match].has_arg ==
                                   required_argument) {
                                /*
                                 * optional argument doesn't use next nargv
                                 */
-                               i_optarg_ = nargv[i_optind_++];
+                               lce_optarg_ = nargv[lce_optind_++];
                        }
                }
                if ((long_options[match].has_arg == required_argument)
-                   && (i_optarg_ == NULL)) {
+                   && (lce_optarg_ == NULL)) {
                        /*
                         * Missing argument; leading ':' indicates no error
                         * should be generated.
                         */
-                       if (I_PRINT_ERROR_)
-                               i_warnx_(i_recargstring_,
+                       if (LCE_PRINT_ERROR_)
+                               lce_warnx_(lce_recargstring_,
                                         current_argv);
                        /*
                         * XXX: GNU sets optopt to val regardless of flag
                         */
                        if (long_options[match].flag == NULL)
-                               i_optopt_ = long_options[match].val;
+                               lce_optopt_ = long_options[match].val;
                        else
-                               i_optopt_ = 0;
-                       --i_optind_;
-                       return (I_BADARG_);
+                               lce_optopt_ = 0;
+                       --lce_optind_;
+                       return (LCE_BADARG_);
                }
        } else {                        /* unknown option */
                if (short_too) {
-                       --i_optind_;
+                       --lce_optind_;
                        return (-1);
                }
-               if (I_PRINT_ERROR_)
-                       i_warnx_(i_illoptstring_, current_argv);
-               i_optopt_ = 0;
-               return (I_BADCH_);
+               if (LCE_PRINT_ERROR_)
+                       lce_warnx_(lce_illoptstring_, current_argv);
+               lce_optopt_ = 0;
+               return (LCE_BADCH_);
        }
        if (idx)
                *idx = match;
@@ -336,11 +339,11 @@ i_parse_long_options__(char * const *nargv, const char *options,
 }
 
 /*
- * i_getopt_internal_ --
+ * lce_getopt_internal_ --
  *     Parse argc/argv argument vector.  Called by user level routines.
  */
 static int
-i_getopt_internal_(int nargc, char *const *nargv, const char *options,
+lce_getopt_internal_(int nargc, char *const *nargv, const char *options,
                   const struct option *long_options, int *idx, int flags)
 {
        char *oli;                              /* option letter list index */
@@ -350,63 +353,63 @@ i_getopt_internal_(int nargc, char *const *nargv, const char *options,
        if (options == NULL)
                return (-1);
 
-       i_progname_ = nargv[0];
+       lce_progname_ = nargv[0];
 
        /*
         * XXX Some GNU programs (like cvs) set optind to 0 instead of
         * XXX using optreset. Work around this braindamage.
         */
-       if (i_optind_ == 0)
-               i_optind_ = i_optreset_ = 1;
+       if (lce_optind_ == 0)
+               lce_optind_ = lce_optreset_ = 1;
 
        /*
         * Disable GNU extensions if POSIXLY_CORRECT is set or options
         * string begins with a '+'.
         */
-       if (posix_me_harder == -1 || i_optreset_)
+       if (posix_me_harder == -1 || lce_optreset_)
                posix_me_harder = (getenv("POSIXLY_CORRECT") != NULL);
        if (*options == '-')
-               flags |= I_FLAG_ALLARGS_;
+               flags |= LCE_FLAG_ALLARGS_;
        else if (posix_me_harder || *options == '+')
-               flags &= ~I_FLAG_PERMUTE_;
+               flags &= ~LCE_FLAG_PERMUTE_;
        if (*options == '+' || *options == '-')
                options++;
 
-       i_optarg_ = NULL;
-       if (i_optreset_)
-               i_nonopt_start_ = i_nonopt_end_ = -1;
+       lce_optarg_ = NULL;
+       if (lce_optreset_)
+               lce_nonopt_start_ = lce_nonopt_end_ = -1;
 start:
-       if (i_optreset_ || !*i_place_) {                /* update scanning pointer */
-               i_optreset_ = 0;
-               if (i_optind_ >= nargc) {               /* end of argument vector */
-                       i_place_ = I_EMSG_;
-                       if (i_nonopt_end_ != -1) {
+       if (lce_optreset_ || !*lce_place_) {                /* update scanning pointer */
+               lce_optreset_ = 0;
+               if (lce_optind_ >= nargc) {               /* end of argument vector */
+                       lce_place_ = LCE_EMSG_;
+                       if (lce_nonopt_end_ != -1) {
                                /* do permutation, if we have to */
-                               i_permute_args_(i_nonopt_start_, i_nonopt_end_,
-                                               i_optind_, nargv);
-                               i_optind_ -= i_nonopt_end_ - i_nonopt_start_;
-                       } else if (i_nonopt_start_ != -1) {
+                               lce_permute_args_(lce_nonopt_start_, lce_nonopt_end_,
+                                               lce_optind_, nargv);
+                               lce_optind_ -= lce_nonopt_end_ - lce_nonopt_start_;
+                       } else if (lce_nonopt_start_ != -1) {
                                /*
                                 * If we skipped non-options, set optind
                                 * to the first of them.
                                 */
-                               i_optind_ = i_nonopt_start_;
+                               lce_optind_ = lce_nonopt_start_;
                        }
-                       i_nonopt_start_ = i_nonopt_end_ = -1;
+                       lce_nonopt_start_ = lce_nonopt_end_ = -1;
                        return (-1);
                }
-               if (*(i_place_ = nargv[i_optind_]) != '-' ||
-                   (i_place_[1] == '\0' && strchr(options, '-') == NULL)) {
-                       i_place_ = I_EMSG_;             /* found non-option */
-                       if (flags & I_FLAG_ALLARGS_) {
+               if (*(lce_place_ = nargv[lce_optind_]) != '-' ||
+                   (lce_place_[1] == '\0' && strchr(options, '-') == NULL)) {
+                       lce_place_ = LCE_EMSG_;             /* found non-option */
+                       if (flags & LCE_FLAG_ALLARGS_) {
                                /*
                                 * GNU extension:
                                 * return non-option as argument to option 1
                                 */
-                               i_optarg_ = nargv[i_optind_++];
-                               return (I_INORDER_);
+                               lce_optarg_ = nargv[lce_optind_++];
+                               return (LCE_INORDER_);
                        }
-                       if (!(flags & I_FLAG_PERMUTE_)) {
+                       if (!(flags & LCE_FLAG_PERMUTE_)) {
                                /*
                                 * If no permutation wanted, stop parsing
                                 * at first non-option.
@@ -414,40 +417,40 @@ start:
                                return (-1);
                        }
                        /* do permutation */
-                       if (i_nonopt_start_ == -1) {
-                               i_nonopt_start_ = i_optind_;
-                       } else if (i_nonopt_end_ != -1) {
-                               i_permute_args_(i_nonopt_start_, i_nonopt_end_,
-                                               i_optind_, nargv);
-                               i_nonopt_start_ = i_optind_ -
-                                                 (i_nonopt_end_ -
-                                                  i_nonopt_start_);
-                               i_nonopt_end_ = -1;
+                       if (lce_nonopt_start_ == -1) {
+                               lce_nonopt_start_ = lce_optind_;
+                       } else if (lce_nonopt_end_ != -1) {
+                               lce_permute_args_(lce_nonopt_start_, lce_nonopt_end_,
+                                               lce_optind_, nargv);
+                               lce_nonopt_start_ = lce_optind_ -
+                                                 (lce_nonopt_end_ -
+                                                  lce_nonopt_start_);
+                               lce_nonopt_end_ = -1;
                        }
-                       i_optind_++;
+                       lce_optind_++;
                        /* process next argument */
                        goto start;
                }
-               if (i_nonopt_start_ != -1 && i_nonopt_end_ == -1)
-                       i_nonopt_end_ = i_optind_;
+               if (lce_nonopt_start_ != -1 && lce_nonopt_end_ == -1)
+                       lce_nonopt_end_ = lce_optind_;
 
                /*
                 * If we have "-" do nothing, if "--" we are done.
                 */
-               if (i_place_[1] != '\0' && *++i_place_ == '-' && i_place_[1] ==
+               if (lce_place_[1] != '\0' && *++lce_place_ == '-' && lce_place_[1] ==
                    '\0') {
-                       i_optind_++;
-                       i_place_ = I_EMSG_;
+                       lce_optind_++;
+                       lce_place_ = LCE_EMSG_;
                        /*
                         * We found an option (--), so if we skipped
                         * non-options, we have to permute.
                         */
-                       if (i_nonopt_end_ != -1) {
-                               i_permute_args_(i_nonopt_start_, i_nonopt_end_,
-                                               i_optind_, nargv);
-                               i_optind_ -= i_nonopt_end_ - i_nonopt_start_;
+                       if (lce_nonopt_end_ != -1) {
+                               lce_permute_args_(lce_nonopt_start_, lce_nonopt_end_,
+                                               lce_optind_, nargv);
+                               lce_optind_ -= lce_nonopt_end_ - lce_nonopt_start_;
                        }
-                       i_nonopt_start_ = i_nonopt_end_ = -1;
+                       lce_nonopt_start_ = lce_nonopt_end_ = -1;
                        return (-1);
                }
        }
@@ -456,93 +459,93 @@ start:
         * Check long options if:
         *  1) we were passed some
         *  2) the arg is not just "-"
-        *  3) either the arg starts with -- we are i_getopt_long_only()
+        *  3) either the arg starts with -- we are lce_getopt_long_only()
         */
-       if (long_options != NULL && i_place_ != nargv[i_optind_] &&
-           (*i_place_ == '-' || (flags & I_FLAG_LONGONLY_))) {
+       if (long_options != NULL && lce_place_ != nargv[lce_optind_] &&
+           (*lce_place_ == '-' || (flags & LCE_FLAG_LONGONLY_))) {
                short_too = 0;
-               if (*i_place_ == '-')
-                       i_place_++;     /* --foo long option */
-               else if (*i_place_ != ':'
-                        && strchr(options, *i_place_) != NULL)
+               if (*lce_place_ == '-')
+                       lce_place_++;     /* --foo long option */
+               else if (*lce_place_ != ':'
+                        && strchr(options, *lce_place_) != NULL)
                        short_too = 1;  /* could be short option too */
 
-               optchar = i_parse_long_options__(nargv, options, long_options,
+               optchar = lce_parse_long_options__(nargv, options, long_options,
                                                 idx, short_too);
                if (optchar != -1) {
-                       i_place_ = I_EMSG_;
+                       lce_place_ = LCE_EMSG_;
                        return (optchar);
                }
        }
 
-       if ((optchar = (int) *i_place_++) == (int) ':' ||
-           (optchar == (int) '-' && *i_place_ != '\0') ||
+       if ((optchar = (int) *lce_place_++) == (int) ':' ||
+           (optchar == (int) '-' && *lce_place_ != '\0') ||
            (oli = strchr(options, optchar)) == NULL) {
                /*
                 * If the user specified "-" and  '-' isn't listed in
                 * options, return -1 (non-option) as per POSIX.
                 * Otherwise, it is an unknown option character (or ':').
                 */
-               if (optchar == (int) '-' && *i_place_ == '\0')
+               if (optchar == (int) '-' && *lce_place_ == '\0')
                        return (-1);
-               if (!*i_place_)
-                       ++i_optind_;
-               if (I_PRINT_ERROR_)
-                       i_warnx_(i_illoptchar_, optchar);
-               i_optopt_ = optchar;
-               return (I_BADCH_);
+               if (!*lce_place_)
+                       ++lce_optind_;
+               if (LCE_PRINT_ERROR_)
+                       lce_warnx_(lce_illoptchar_, optchar);
+               lce_optopt_ = optchar;
+               return (LCE_BADCH_);
        }
        if (long_options != NULL && optchar == 'W' && oli[1] == ';') {
                /* -W long-option */
-               if (*i_place_) {                        /* no space */
+               if (*lce_place_) {                        /* no space */
                        /* NOTHING */
                        ;
-               } else if (++i_optind_ >= nargc) {      /* no arg */
-                       i_place_ = I_EMSG_;
-                       if (I_PRINT_ERROR_)
-                               i_warnx_(i_recargchar_, optchar);
-                       i_optopt_ = optchar;
-                       return (I_BADARG_);
+               } else if (++lce_optind_ >= nargc) {      /* no arg */
+                       lce_place_ = LCE_EMSG_;
+                       if (LCE_PRINT_ERROR_)
+                               lce_warnx_(lce_recargchar_, optchar);
+                       lce_optopt_ = optchar;
+                       return (LCE_BADARG_);
                } else {                                /* white space */
-                       i_place_ = nargv[i_optind_];
+                       lce_place_ = nargv[lce_optind_];
                }
-               optchar = i_parse_long_options__(nargv, options, long_options,
+               optchar = lce_parse_long_options__(nargv, options, long_options,
                                                 idx, 0);
-               i_place_ = I_EMSG_;
+               lce_place_ = LCE_EMSG_;
                return (optchar);
        }
        if (*++oli != ':') {                            /* doesn't take argument */
-               if (!*i_place_)
-                       ++i_optind_;
+               if (!*lce_place_)
+                       ++lce_optind_;
        } else {                                        /* takes (optional) argument */
-               i_optarg_ = NULL;
-               if (*i_place_){                         /* no white space */
-                       i_optarg_ = i_place_;
+               lce_optarg_ = NULL;
+               if (*lce_place_){                         /* no white space */
+                       lce_optarg_ = lce_place_;
                } else if (oli[1] != ':'){              /* arg not optional */
-                       if (++i_optind_ >= nargc) {     /* no arg */
-                               i_place_ = I_EMSG_;
-                               if (I_PRINT_ERROR_)
-                                       i_warnx_(i_recargchar_, optchar);
-                               i_optopt_ = optchar;
-                               return (I_BADARG_);
+                       if (++lce_optind_ >= nargc) {     /* no arg */
+                               lce_place_ = LCE_EMSG_;
+                               if (LCE_PRINT_ERROR_)
+                                       lce_warnx_(lce_recargchar_, optchar);
+                               lce_optopt_ = optchar;
+                               return (LCE_BADARG_);
                        } else {
-                               i_optarg_ = nargv[i_optind_];
+                               lce_optarg_ = nargv[lce_optind_];
                        }
                }
-               i_place_ = I_EMSG_;
-               ++i_optind_;
+               lce_place_ = LCE_EMSG_;
+               ++lce_optind_;
        }
        /* dump back option letter */
        return (optchar);
 }
 
 int
-i_getsubopt_(char **optionp, char * const *tokens, char **valuep)
+lce_getsubopt_(char **optionp, char * const *tokens, char **valuep)
 {
        int cnt;
        char *p;
 
-       i_suboptarg_ = *valuep = NULL;
+       lce_suboptarg_ = *valuep = NULL;
 
        if (!optionp || !*optionp)
                return (-1);
@@ -556,7 +559,7 @@ i_getsubopt_(char **optionp, char * const *tokens, char **valuep)
        }
 
        /* save the start of the token, and skip the rest of the token. */
-       for (i_suboptarg_ = p;
+       for (lce_suboptarg_ = p;
             *++p && *p != ',' && *p != '=' && *p != ' ' && *p != '\t';) ;
 
        if (*p) {
@@ -582,46 +585,46 @@ i_getsubopt_(char **optionp, char * const *tokens, char **valuep)
        *optionp = p;
 
        for (cnt = 0; *tokens; ++tokens, ++cnt)
-               if (!strcmp(i_suboptarg_, *tokens))
+               if (!strcmp(lce_suboptarg_, *tokens))
                        return (cnt);
        return (-1);
 }
 
 int
-i_getopt_(int argc, char * const *argv, const char *optstring)
+lce_getopt_(int argc, char * const *argv, const char *optstring)
 {
-#ifdef GETOPT_PERMUTE_ARGS
-       return (i_getopt_internal_(argc, argv, optstring, NULL, NULL,
-                                  I_FLAG_PERMUTE_));
+#ifdef LCE_GETOPT_PERMUTE_ARGS
+       return (lce_getopt_internal_(argc, argv, optstring, NULL, NULL,
+                                  LCE_FLAG_PERMUTE_));
 #else
-       return (i_getopt_internal_(argc, argv, optstring, NULL, NULL, 0));
-#endif
+       return (lce_getopt_internal_(argc, argv, optstring, NULL, NULL, 0));
+#endif /* LCE_GETOPT_PERMUTE_ARGS */
 }
 
 int
-i_getopt_long_(int argc, char * const *argv, const char *optstring,
+lce_getopt_long_(int argc, char * const *argv, const char *optstring,
               const struct option *longopts, int *longindex)
 {
-#ifdef GETOPT_LONG_PERMUTE_ARGS
-       return (i_getopt_internal_(argc, argv, optstring, longopts, longindex,
-                                  I_FLAG_PERMUTE_));
+#ifdef LCE_GETOPT_LONG_PERMUTE_ARGS
+       return (lce_getopt_internal_(argc, argv, optstring, longopts, longindex,
+                                  LCE_FLAG_PERMUTE_));
 #else
-       return (i_getopt_internal_(argc, argv, optstring, longopts, longindex, 0
+       return (lce_getopt_internal_(argc, argv, optstring, longopts, longindex, 0
                                   ));
-#endif
+#endif /* LCE_GETOPT_LONG_PERMUTE_ARGS */
 }
 
 int
-i_getopt_long_only_(int argc, char * const *argv, const char *optstring,
+lce_getopt_long_only_(int argc, char * const *argv, const char *optstring,
                    const struct option *longopts, int *longindex)
 {
-#ifdef GETOPT_LONG_ONLY_PERMUTE_ARGS
-       return (i_getopt_internal_(argc, argv, optstring, longopts, longindex,
-                                  I_FLAG_PERMUTE_ | I_FLAG_LONGONLY_));
+#ifdef LCE_GETOPT_LONG_ONLY_PERMUTE_ARGS
+       return (lce_getopt_internal_(argc, argv, optstring, longopts, longindex,
+                                  LCE_FLAG_PERMUTE_ | I_FLAG_LONGONLY_));
 #else
-       return (i_getopt_internal_(argc, argv, optstring, longopts, longindex,
-                                  I_FLAG_LONGONLY_));
-#endif
+       return (lce_getopt_internal_(argc, argv, optstring, longopts, longindex,
+                                  LCE_FLAG_LONGONLY_));
+#endif /* LCE_GETOPT_LONG_ONLY_PERMUTE_ARGS */
 }
- #endif /* GETOPT_LONG_IMPLEMENTATION */
-#endif /* !GETOPT_LONG_H_ */
+ #endif /* LCE_GETOPT_LONG_IMPLEMENTATION */
+#endif /* !LCE_GETOPT_LONG_H */
index b7f1e3eec9caed5015916183edbd0c12d11d09d7..3d9f769ac21e1be42f1b80bbe96ffb1e668bde94 100644 (file)
--- a/strdup.h
+++ b/strdup.h
  */
 
 /* https://git.datadissipation.net */
-#ifndef STRDUP_H_
- #define STRDUP_H_      1
+#ifndef LCE_STRDUP_H
+ #define LCE_STRDUP_H      1
 
- #ifdef STRDUP_INCLUDE_LIBC
+ #ifdef LCE_STRDUP_INCLUDE_LIBC
   #include <stdlib.h>
   #include <string.h>
- #endif /* STRDUP_INCLUDE_LIBC */
+ #endif /* LCE_STRDUP_INCLUDE_LIBC */
 
  #ifndef HAVE_STRDUP
   #define HAVE_STRDUP   1
-  #define strdup        i_strdup_
-  #define strndup       i_strndup_
-char *i_strdup_(const char *s);
-char *i_strndup_(const char *s, size_t n);
+  #define strdup        lce_strdup_
+  #define strndup       lce_strndup_
+char *lce_strdup_(const char *s);
+char *lce_strndup_(const char *s, size_t n);
  #endif /* !HAVE_STRDUP */
 
- #ifdef STRDUP_IMPLEMENTATION
+ #ifdef LCE_STRDUP_IMPLEMENTATION
 char *
-i_strdup_(const char *s)
+lce_strdup_(const char *s)
 {
        /* avoid calling strlen twice by passing the maximum */
-       return i_strndup_(s, ~(size_t)0);
+       return lce_strndup_(s, ~(size_t)0);
 }
 
 char *
-i_strndup_(const char *s, size_t n)
+lce_strndup_(const char *s, size_t n)
 {
        char *d;
        size_t t;
@@ -65,5 +65,5 @@ i_strndup_(const char *s, size_t n)
 
        return memcpy(d, s, t - 1);
 }
- #endif /* STRDUP_IMPLEMENTATION */
-#endif /* !STRDUP_H_ */
+ #endif /* LCE_STRDUP_IMPLEMENTATION */
+#endif /* !LCE_STRDUP_H */
index 68882856e5111e94fcf1e47cfaf06e2fe90935d4..f1a035d46245481962496912706c1e0adb406c5b 100644 (file)
--- a/strlcat.h
+++ b/strlcat.h
  */
 
 /* https://git.datadissipation.net */
-#ifndef STRLCAT_H_
- #define STRLCAT_H_     1
+#ifndef LCE_STRLCAT_H
+ #define LCE_STRLCAT_H     1
 
- #ifdef STRLCAT_INCLUDE_LIBC
+ #ifdef LCE_STRLCAT_INCLUDE_LIBC
   #include <stdio.h>
   #include <string.h>
- #endif /* !STRLCAT_INCLUDE_LIBC */
+ #endif /* !LCE_STRLCAT_INCLUDE_LIBC */
 
  #ifndef HAVE_STRLCAT
   #define HAVE_STRLCAT  1
-  #define strlcat       i_strlcat_
-  #define strlcpy       i_strlcpy_
-size_t i_strlcat_(char *dst, const char *src, size_t siz);
-size_t i_strlcpy_(char *dst, const char *src, size_t siz);
+  #define strlcat       lce_strlcat_
+  #define strlcpy       lce_strlcpy_
+size_t lce_strlcat_(char *dst, const char *src, size_t siz);
+size_t lce_strlcpy_(char *dst, const char *src, size_t siz);
  #endif /* !HAVE_STRLCAT */
 
- #ifdef STRLCAT_IMPLEMENTATION
+ #ifdef LCE_STRLCAT_IMPLEMENTATION
 /*
  * Appends src to string dst of size siz (unlike strncat, siz is the
  * full size of dst, not space left). At most siz-1 characters
@@ -40,7 +40,7 @@ size_t i_strlcpy_(char *dst, const char *src, size_t siz);
  * If retval >= siz, truncation occurred.
  */
 size_t
-i_strlcat_(char *dst, const char *src, size_t siz)
+lce_strlcat_(char *dst, const char *src, size_t siz)
 {
        char *d = dst;
        const char *s = src;
@@ -70,7 +70,7 @@ i_strlcat_(char *dst, const char *src, size_t siz)
  * Returns strlen(src); if retval >= siz, truncation occurred.
  */
 size_t
-i_strlcpy_(char *dst, const char *src, size_t siz)
+lce_strlcpy_(char *dst, const char *src, size_t siz)
 {
        char *d = dst;
        const char *s = src;
@@ -91,5 +91,5 @@ i_strlcpy_(char *dst, const char *src, size_t siz)
        }
        return(s - src - 1); /* count does not include NUL */
 }
- #endif /* STRLCAT_IMPLEMENTATION */
-#endif /* !STRLCAT_H_ */
+ #endif /* LCE_STRLCAT_IMPLEMENTATION */
+#endif /* !LCE_STRLCAT_H */
index 471aea8b4bf7b766edc4d965433488946b44162b..f192630b1e5a8bff4bf1b3e04da79749ec828ff6 100644 (file)
  */
 
 /* https://git.datadissipation.net */
-#ifndef STRTONUM_H_
- #define STRTONUM_H_            1
+#ifndef LCE_STRTONUM_H
+ #define LCE_STRTONUM_H            1
 
- #ifdef STRTONUM_INCLUDE_LIBC
+ #ifdef LCE_STRTONUM_INCLUDE_LIBC
   #include <errno.h>
   #include <limits.h>
   #include <stdlib.h>
- #endif /* STRTONUM_INCLUDE_LIBC */
+ #endif /* LCE_STRTONUM_INCLUDE_LIBC */
 
  #ifndef HAVE_STRTONUM
- #define strtonum               i_strtonum_
-long long i_strtonum_(const char *numstr, long long minval, long long maxval,
+ #define strtonum               lce_strtonum_
+long long lce_strtonum_(const char *numstr, long long minval, long long maxval,
                      const char **errstrp);
  #endif /* !HAVE_STRTONUM */
 
- #ifdef STRTONUM_IMPLEMENTATION
-  #define      I_INVALID_      1
-  #define      I_TOOSMALL_     2
-  #define      I_TOOLARGE_     3
+ #ifdef LCE_STRTONUM_IMPLEMENTATION
+  #define      LCE_INVALID_    1
+  #define      LCE_TOOSMALL_   2
+  #define      LCE_TOOLARGE_   3
 
 long long
-i_strtonum_(const char *numstr, long long minval, long long maxval,
+lce_strtonum_(const char *numstr, long long minval, long long maxval,
            const char **errstrp)
 {
        long long ll = 0;
@@ -56,15 +56,15 @@ i_strtonum_(const char *numstr, long long minval, long long maxval,
        ev[0].err = errno;
        errno = 0;
        if (minval > maxval) {
-               error = I_INVALID_;
+               error = LCE_INVALID_;
        } else {
                ll = strtoll(numstr, &ep, 10);
                if (numstr == ep || *ep != '\0')
-                       error = I_INVALID_;
+                       error = LCE_INVALID_;
                else if ((ll == LLONG_MIN && errno == ERANGE) || ll < minval)
-                       error = I_TOOSMALL_;
+                       error = LCE_TOOSMALL_;
                else if ((ll == LLONG_MAX && errno == ERANGE) || ll > maxval)
-                       error = I_TOOLARGE_;
+                       error = LCE_TOOLARGE_;
        }
        if (errstrp != NULL)
                *errstrp = ev[error].errstr;
@@ -74,5 +74,5 @@ i_strtonum_(const char *numstr, long long minval, long long maxval,
 
        return (ll);
 }
- #endif /* STRTONUM_IMPLEMENTATION */
-#endif /* !STRTONUM_H_ */
+ #endif /* LCE_STRTONUM_IMPLEMENTATION */
+#endif /* !LCE_STRTONUM_H */