#endif
#include <stdio.h>
-#include <string.h>
/* Comment out all this code if we are using the GNU C Library, and are not
actually compiling the library itself. This code is part of the GNU C
#include <string.h>
#define my_index strchr
#define my_strlen strlen
+#define my_strcmp strcmp
+#define my_strncmp strncmp
#else
/* Avoid depending on library functions or files
#if __STDC__ || defined(PROTO)
extern char *getenv(const char *name);
-extern int strcmp(const char *s1, const char *s2);
-extern int strncmp(const char *s1, const char *s2, int n);
static int my_strlen(const char *s);
static char *my_index(const char *str, int chr);
+static int my_strncmp(const char *s1, const char *s2, int n);
+static int my_strcmp(const char *s1, const char *s2);
#else
extern char *getenv();
#endif
return 0;
}
+static int my_strncmp(const char *s1, const char *s2, int n)
+{
+ while (n && *s1 && (*s1 == *s2)) {
+ ++s1;
+ ++s2;
+ --n;
+ }
+ if (n == 0)
+ return 0;
+ return *(const unsigned char *)s1 - *(const unsigned char *)s2;
+}
+
+static int my_strcmp(const char *s1, const char *s2)
+{
+ return my_strncmp(s1, s2, -1);
+}
+
#endif /* GNU C library. */
\f
/* Handle permutation of arguments. */
then exchange with previous non-options as if it were an option,
then skip everything else like a non-option. */
- if (optind != argc && !strcmp(argv[optind], "--")) {
+ if (optind != argc && !my_strcmp(argv[optind], "--")) {
optind++;
if (first_nonopt != last_nonopt && last_nonopt != optind)
/* Test all options for either exact match or abbreviated matches. */
for (p = longopts, option_index = 0; p->name; p++, option_index++)
- if (!strncmp(p->name, nextchar, s - nextchar)) {
+ if (!my_strncmp(p->name, nextchar, s - nextchar)) {
if (s - nextchar == my_strlen(p->name)) {
/* Exact match found. */
pfound = p;
#define optional_argument 2
#if __STDC__ || defined(PROTO)
-#if defined(__GNU_LIBRARY__)
-/* Many other libraries have conflicting prototypes for getopt, with
- differences in the consts, in stdlib.h. To avoid compilation
- errors, only prototype getopt for the GNU C library. */
extern int getopt (int argc, char *const *argv, const char *shortopts);
-#endif /* not __GNU_LIBRARY__ */
extern int getopt_long (int argc, char *const *argv, const char *shortopts,
const struct option *longopts, int *longind);
extern int getopt_long_only (int argc, char *const *argv,