]> git.sur5r.net Git - bacula/bacula/commitdiff
Integrate most of the MinGW changes -- more to do.
authorKern Sibbald <kern@sibbald.com>
Sat, 22 Apr 2006 09:13:07 +0000 (09:13 +0000)
committerKern Sibbald <kern@sibbald.com>
Sat, 22 Apr 2006 09:13:07 +0000 (09:13 +0000)
git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@2957 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/kes-1.39
bacula/src/lib/bsys.c
bacula/src/version.h
bacula/src/win32/compat/compat.cpp
bacula/src/win32/compat/compat.h
bacula/src/win32/compat/getopt.c

index e4cfdb04f185520dd7cbfef33d14cc67f226d73a..6e80941f73bd7298ed0bd8912dd0a230cc218b5b 100644 (file)
@@ -2,6 +2,8 @@
                         Kern Sibbald
 
 General:
+22Apr06
+- Integrate most of the MinGW changes -- more to do.
 21Apr06
 - Implement using pg_config for finding PostgreSQL files.
   Fixes bug #600. Patch supplied by user.
index c620740a5a59d6881affb1e786d3a1f85957e4dc..548ab97b2a6fbdb4ba562230f641f709ada893cd 100644 (file)
@@ -183,7 +183,8 @@ void *bmalloc(size_t size)
 
   buf = malloc(size);
   if (buf == NULL) {
-     Emsg1(M_ABORT, 0, _("Out of memory: ERR=%s\n"), strerror(errno));
+     berrno be;
+     Emsg1(M_ABORT, 0, _("Out of memory: ERR=%s\n"), be.strerror());
   }
   return buf;
 }
@@ -199,7 +200,8 @@ void *b_malloc(const char *file, int line, size_t size)
   buf = malloc(size);
 #endif
   if (buf == NULL) {
-     e_msg(file, line, M_ABORT, 0, _("Out of memory: ERR=%s\n"), strerror(errno));
+     berrno be;
+     e_msg(file, line, M_ABORT, 0, _("Out of memory: ERR=%s\n"), be.strerror());
   }
   return buf;
 }
@@ -209,7 +211,8 @@ void *brealloc (void *buf, size_t size)
 {
    buf = realloc(buf, size);
    if (buf == NULL) {
-      Emsg1(M_ABORT, 0, _("Out of memory: ERR=%s\n"), strerror(errno));
+      berrno be;
+      Emsg1(M_ABORT, 0, _("Out of memory: ERR=%s\n"), be.strerror());
    }
    return buf;
 }
@@ -221,7 +224,8 @@ void *bcalloc (size_t size1, size_t size2)
 
    buf = calloc(size1, size2);
    if (buf == NULL) {
-      Emsg1(M_ABORT, 0, _("Out of memory: ERR=%s\n"), strerror(errno));
+      berrno be;
+      Emsg1(M_ABORT, 0, _("Out of memory: ERR=%s\n"), be.strerror());
    }
    return buf;
 }
index d69c8365620a94a042f376020d4bdc03b0a601c7..703fd04794797a63c4acf2e3770a68577bc0ae1a 100644 (file)
@@ -4,8 +4,8 @@
 
 #undef  VERSION
 #define VERSION "1.39.9"
-#define BDATE   "21 April 2006"
-#define LSMDATE "21Apr06"
+#define BDATE   "22 April 2006"
+#define LSMDATE "22Apr06"
 
 /* Debug flags */
 #undef  DEBUG
index 69a20393aed943cfb5f0b5d557def8fec72285bd..894c3ed47ef426ca0c9ca1ad535cd9bdd8dc3200 100644 (file)
@@ -1130,7 +1130,7 @@ win32_mkdir(const char *dir)
       POOLMEM* pwszBuf = get_pool_memory(PM_FNAME);
       make_win32_path_UTF8_2_wchar(&pwszBuf, dir);
 
-      int n=p_wmkdir((LPCWSTR)pwszBuf);
+      int n = p_wmkdir((LPCWSTR)pwszBuf);
       free_pool_memory(pwszBuf);
       return n;
    }
index 51226006254606289c68bf3403f1b7495de65d65..fc262b829ee6fb87dc7b61ea4605a1b73e372cd4 100644 (file)
@@ -90,13 +90,16 @@ typedef UINT64 u_int64_t;
 typedef UINT64 uint64_t;
 typedef INT64 int64_t;
 typedef UINT32 uint32_t;
-typedef long int32_t;
 typedef INT64 intmax_t;
 typedef unsigned char uint8_t;
-typedef float float32_t;
 typedef unsigned short uint16_t;
 typedef signed short int16_t;
 typedef signed char int8_t;
+#ifndef HAVE_MINGW
+typedef long int32_t;
+typedef float float32_t;
+typedef double float64_t;
+#endif
 
 #ifndef HAVE_VC8
 typedef long time_t;
@@ -121,7 +124,6 @@ typedef int BOOL;
 #endif
 #endif
 
-typedef double float64_t;
 typedef UINT32 u_int32_t;
 typedef unsigned char u_int8_t;
 typedef unsigned short u_int16_t;
@@ -146,7 +148,7 @@ typedef UINT32 mode_t;
 /* #ifndef _WX_DEFS_H_  ssize_t is defined in wx/defs.h */
 typedef INT64  ssize_t;
 /* #endif */
-#endif //HAVE_MINGW
+#endif /* HAVE_MINGW */
 
 struct dirent {
     uint64_t    d_ino;
@@ -171,12 +173,12 @@ struct timezone {
 };
 
 int strcasecmp(const char*, const char *);
-int strncasecmp(const char*, const char *, int);
 int gettimeofday(struct timeval *, struct timezone *);
 
 #define ETIMEDOUT 55
 
 #ifndef HAVE_MINGW
+int strncasecmp(const char*, const char *, int);
 
 #ifndef _STAT_DEFINED
 struct stat
@@ -250,18 +252,22 @@ struct stat
 #endif
 
 #ifndef HAVE_VC8
+#ifndef HAVE_MINGW
 int umask(int);
 off_t lseek(int, off_t, int);
 int dup2(int, int);
 int close(int fd);
-#ifndef HAVE_WXCONSOLE
+#endif
+#if !defined(HAVE_WXCONSOLE) && !defined(HAVE_MINGW)
 ssize_t read(int fd, void *, ssize_t nbytes);
 ssize_t write(int fd, const void *, ssize_t nbytes);
 #endif
 #endif
 int lchown(const char *, uid_t uid, gid_t gid);
 int chown(const char *, uid_t uid, gid_t gid);
+#ifndef HAVE_MINGW
 int chmod(const char *, mode_t mode);
+#endif
 int inet_aton(const char *cp, struct in_addr *inp);
 int kill(int pid, int signo);
 int pipe(int []);
@@ -295,6 +301,7 @@ int __sprintf(char *str, const char *fmt, ...);
 
 #define HAVE_OLD_SOCKOPT
 
+struct timespec;
 int readdir(unsigned int fd, struct dirent *dirp, unsigned int count);
 int nanosleep(const struct timespec*, struct timespec *);
 struct tm *localtime_r(const time_t *, struct tm *);
index 2ea01c161354945d424ca10e53aab940cad8c8b5..f5f676ad5100910dc0a709528f882ef61117ba86 100644 (file)
@@ -4,7 +4,7 @@
    before changing it!
 
    Copyright (C) 1987, 88, 89, 90, 91, 92, 1993
-       Free Software Foundation, Inc.
+        Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by the
@@ -35,7 +35,7 @@
 #include "config.h"
 #endif
 
-#ifdef __GNUC__
+#if  defined(__GNUC__) && !defined(alloca)
 #define alloca __builtin_alloca
 #else /* not __GNUC__ */
 #if defined (HAVE_ALLOCA_H) || (defined(sparc) && (defined(sun) || (!defined(USG) && !defined(SVR4) && !defined(__svr4__))))
@@ -71,14 +71,14 @@ char *alloca ();
 
 /* This needs to come after some library #include
    to get __GNU_LIBRARY__ defined.  */
-#ifdef __GNU_LIBRARY__
-#undef alloca
+#ifdef  __GNU_LIBRARY__
+#undef  alloca
 /* Don't include stdlib.h for non-GNU C libraries because some of them
    contain conflicting prototypes for getopt.  */
 #include <stdlib.h>
-#else  /* Not GNU C library.  */
-#define        __alloca        alloca
-#endif /* GNU C library.  */
+#else   /* Not GNU C library.  */
+#define __alloca        alloca
+#endif  /* GNU C library.  */
 
 /* If GETOPT_COMPAT is defined, `+' as well as `--' can introduce a
    long-named option.  Because this is not POSIX.2 compliant, it is
@@ -178,14 +178,14 @@ static enum
   REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
 } ordering;
 \f
-#ifdef __GNU_LIBRARY__
+#ifdef  __GNU_LIBRARY__
 /* We want to avoid inclusion of string.h with non-GNU libraries
    because there are many ways it can cause trouble.
    On some systems, it contains special magic macros that don't work
    in GCC.  */
 #include <string.h>
-#define        my_index        strchr
-#define        my_bcopy(src, dst, n)   memcpy ((dst), (src), (n))
+#define my_index        strchr
+#define my_bcopy(src, dst, n)   memcpy ((dst), (src), (n))
 #else
 
 /* Avoid depending on library functions or files
@@ -206,7 +206,7 @@ my_index (const char *str, int chr)
   while (*str)
     {
       if (*str == chr)
-       return (char *) str;
+        return (char *) str;
       str++;
     }
   return 0;
@@ -227,7 +227,7 @@ my_bcopy (const char *from, char *to, int size)
   for (i = 0; i < size; i++)
     to[i] = from[i];
 }
-#endif                         /* GNU C library.  */
+#endif                          /* GNU C library.  */
 \f
 /* Handle permutation of arguments.  */
 
@@ -257,10 +257,10 @@ exchange (char **argv)
 
   my_bcopy ((char *) &argv[first_nonopt], (char *) temp, nonopts_size);
   my_bcopy ((char *) &argv[last_nonopt], (char *) &argv[first_nonopt],
-           (optind - last_nonopt) * sizeof (char *));
+            (optind - last_nonopt) * sizeof (char *));
   my_bcopy ((char *) temp,
-           (char *) &argv[first_nonopt + optind - last_nonopt],
-           nonopts_size);
+            (char *) &argv[first_nonopt + optind - last_nonopt],
+            nonopts_size);
 
   /* Update records for the slots the non-options now occupy.  */
 
@@ -351,107 +351,107 @@ _getopt_internal (
       /* Determine how to handle the ordering of options and nonoptions.  */
 
       if (optstring[0] == '-')
-       {
-         ordering = RETURN_IN_ORDER;
-         ++optstring;
-       }
+        {
+          ordering = RETURN_IN_ORDER;
+          ++optstring;
+        }
       else if (optstring[0] == '+')
-       {
-         ordering = REQUIRE_ORDER;
-         ++optstring;
-       }
+        {
+          ordering = REQUIRE_ORDER;
+          ++optstring;
+        }
       else if (getenv ("POSIXLY_CORRECT") != NULL)
-       ordering = REQUIRE_ORDER;
+        ordering = REQUIRE_ORDER;
       else
-       ordering = PERMUTE;
+        ordering = PERMUTE;
     }
 
   if (nextchar == NULL || *nextchar == '\0')
     {
       if (ordering == PERMUTE)
-       {
-         /* If we have just processed some options following some non-options,
-            exchange them so that the options come first.  */
+        {
+          /* If we have just processed some options following some non-options,
+             exchange them so that the options come first.  */
 
-         if (first_nonopt != last_nonopt && last_nonopt != optind)
-           exchange ((char **) argv);
-         else if (last_nonopt != optind)
-           first_nonopt = optind;
+          if (first_nonopt != last_nonopt && last_nonopt != optind)
+            exchange ((char **) argv);
+          else if (last_nonopt != optind)
+            first_nonopt = optind;
 
-         /* Now skip any additional non-options
-            and extend the range of non-options previously skipped.  */
+          /* Now skip any additional non-options
+             and extend the range of non-options previously skipped.  */
 
-         while (optind < argc
-                && (argv[optind][0] != '-' || argv[optind][1] == '\0')
+          while (optind < argc
+                 && (argv[optind][0] != '-' || argv[optind][1] == '\0')
 #ifdef GETOPT_COMPAT
-                && (longopts == NULL
-                    || argv[optind][0] != '+' || argv[optind][1] == '\0')
-#endif                         /* GETOPT_COMPAT */
-                )
-           optind++;
-         last_nonopt = optind;
-       }
+                 && (longopts == NULL
+                     || argv[optind][0] != '+' || argv[optind][1] == '\0')
+#endif                          /* GETOPT_COMPAT */
+                 )
+            optind++;
+          last_nonopt = optind;
+        }
 
       /* Special ARGV-element `--' means premature end of options.
-        Skip it like a null option,
-        then exchange with previous non-options as if it were an option,
-        then skip everything else like a non-option.  */
+         Skip it like a null option,
+         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], "--"))
-       {
-         optind++;
+        {
+          optind++;
 
-         if (first_nonopt != last_nonopt && last_nonopt != optind)
-           exchange ((char **) argv);
-         else if (first_nonopt == last_nonopt)
-           first_nonopt = optind;
-         last_nonopt = argc;
+          if (first_nonopt != last_nonopt && last_nonopt != optind)
+            exchange ((char **) argv);
+          else if (first_nonopt == last_nonopt)
+            first_nonopt = optind;
+          last_nonopt = argc;
 
-         optind = argc;
-       }
+          optind = argc;
+        }
 
       /* If we have done all the ARGV-elements, stop the scan
-        and back over any non-options that we skipped and permuted.  */
+         and back over any non-options that we skipped and permuted.  */
 
       if (optind == argc)
-       {
-         /* Set the next-arg-index to point at the non-options
-            that we previously skipped, so the caller will digest them.  */
-         if (first_nonopt != last_nonopt)
-           optind = first_nonopt;
-         return EOF;
-       }
+        {
+          /* Set the next-arg-index to point at the non-options
+             that we previously skipped, so the caller will digest them.  */
+          if (first_nonopt != last_nonopt)
+            optind = first_nonopt;
+          return EOF;
+        }
 
       /* If we have come to a non-option and did not permute it,
-        either stop the scan or describe it to the caller and pass it by.  */
+         either stop the scan or describe it to the caller and pass it by.  */
 
       if ((argv[optind][0] != '-' || argv[optind][1] == '\0')
 #ifdef GETOPT_COMPAT
-         && (longopts == NULL
-             || argv[optind][0] != '+' || argv[optind][1] == '\0')
-#endif                         /* GETOPT_COMPAT */
-         )
-       {
-         if (ordering == REQUIRE_ORDER)
-           return EOF;
-         optarg = argv[optind++];
-         return 1;
-       }
+          && (longopts == NULL
+              || argv[optind][0] != '+' || argv[optind][1] == '\0')
+#endif                          /* GETOPT_COMPAT */
+          )
+        {
+          if (ordering == REQUIRE_ORDER)
+            return EOF;
+          optarg = argv[optind++];
+          return 1;
+        }
 
       /* We have found another option-ARGV-element.
-        Start decoding its characters.  */
+         Start decoding its characters.  */
 
       nextchar = (argv[optind] + 1
-                 + (longopts != NULL && argv[optind][1] == '-'));
+                  + (longopts != NULL && argv[optind][1] == '-'));
     }
 
   if (longopts != NULL
       && ((argv[optind][0] == '-'
-          && (argv[optind][1] == '-' || long_only))
+           && (argv[optind][1] == '-' || long_only))
 #ifdef GETOPT_COMPAT
-         || argv[optind][0] == '+'
-#endif                         /* GETOPT_COMPAT */
-         ))
+          || argv[optind][0] == '+'
+#endif                          /* GETOPT_COMPAT */
+          ))
     {
       const struct option *p;
       char *s = nextchar;
@@ -461,119 +461,119 @@ _getopt_internal (
       int indfound = 0 ;
 
       while (*s && *s != '=')
-       s++;
+        s++;
 
       /* 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 ((size_t)(s - nextchar) == strlen (p->name))
-             {
-               /* Exact match found.  */
-               pfound = p;
-               indfound = option_index;
-               exact = 1;
-               break;
-             }
-           else if (pfound == NULL)
-             {
-               /* First nonexact match found.  */
-               pfound = p;
-               indfound = option_index;
-             }
-           else
-             /* Second nonexact match found.  */
-             ambig = 1;
-         }
+           p++, option_index++)
+        if (!strncmp (p->name, nextchar, s - nextchar))
+          {
+            if ((size_t)(s - nextchar) == strlen (p->name))
+              {
+                /* Exact match found.  */
+                pfound = p;
+                indfound = option_index;
+                exact = 1;
+                break;
+              }
+            else if (pfound == NULL)
+              {
+                /* First nonexact match found.  */
+                pfound = p;
+                indfound = option_index;
+              }
+            else
+              /* Second nonexact match found.  */
+              ambig = 1;
+          }
 
       if (ambig && !exact)
-       {
-         if (opterr)
-           fprintf (stderr, "%s: option `%s' is ambiguous\n",
-                    argv[0], argv[optind]);
-         nextchar += strlen (nextchar);
-         optind++;
-         return '?';
-       }
+        {
+          if (opterr)
+            fprintf (stderr, "%s: option `%s' is ambiguous\n",
+                     argv[0], argv[optind]);
+          nextchar += strlen (nextchar);
+          optind++;
+          return '?';
+        }
 
       if (pfound != NULL)
-       {
-         option_index = indfound;
-         optind++;
-         if (*s)
-           {
-             /* Don't test has_arg with >, because some C compilers don't
-                allow it to be used on enums.  */
-             if (pfound->has_arg)
-               optarg = s + 1;
-             else
-               {
-                 if (opterr)
-                   {
-                     if (argv[optind - 1][1] == '-')
-                       /* --option */
-                       fprintf (stderr,
-                                "%s: option `--%s' doesn't allow an argument\n",
-                                argv[0], pfound->name);
-                     else
-                       /* +option or -option */
-                       fprintf (stderr,
-                            "%s: option `%c%s' doesn't allow an argument\n",
-                            argv[0], argv[optind - 1][0], pfound->name);
-                   }
-                 nextchar += strlen (nextchar);
-                 return '?';
-               }
-           }
-         else if (pfound->has_arg == 1)
-           {
-             if (optind < argc)
-               optarg = argv[optind++];
-             else
-               {
-                 if (opterr)
-                   fprintf (stderr, "%s: option `%s' requires an argument\n",
-                            argv[0], argv[optind - 1]);
-                 nextchar += strlen (nextchar);
-                 return optstring[0] == ':' ? ':' : '?';
-               }
-           }
-         nextchar += strlen (nextchar);
-         if (longind != NULL)
-           *longind = option_index;
-         if (pfound->flag)
-           {
-             *(pfound->flag) = pfound->val;
-             return 0;
-           }
-         return pfound->val;
-       }
+        {
+          option_index = indfound;
+          optind++;
+          if (*s)
+            {
+              /* Don't test has_arg with >, because some C compilers don't
+                 allow it to be used on enums.  */
+              if (pfound->has_arg)
+                optarg = s + 1;
+              else
+                {
+                  if (opterr)
+                    {
+                      if (argv[optind - 1][1] == '-')
+                        /* --option */
+                        fprintf (stderr,
+                                 "%s: option `--%s' doesn't allow an argument\n",
+                                 argv[0], pfound->name);
+                      else
+                        /* +option or -option */
+                        fprintf (stderr,
+                             "%s: option `%c%s' doesn't allow an argument\n",
+                             argv[0], argv[optind - 1][0], pfound->name);
+                    }
+                  nextchar += strlen (nextchar);
+                  return '?';
+                }
+            }
+          else if (pfound->has_arg == 1)
+            {
+              if (optind < argc)
+                optarg = argv[optind++];
+              else
+                {
+                  if (opterr)
+                    fprintf (stderr, "%s: option `%s' requires an argument\n",
+                             argv[0], argv[optind - 1]);
+                  nextchar += strlen (nextchar);
+                  return optstring[0] == ':' ? ':' : '?';
+                }
+            }
+          nextchar += strlen (nextchar);
+          if (longind != NULL)
+            *longind = option_index;
+          if (pfound->flag)
+            {
+              *(pfound->flag) = pfound->val;
+              return 0;
+            }
+          return pfound->val;
+        }
       /* Can't find it as a long option.  If this is not getopt_long_only,
-        or the option starts with '--' or is not a valid short
-        option, then it's an error.
-        Otherwise interpret it as a short option.  */
+         or the option starts with '--' or is not a valid short
+         option, then it's an error.
+         Otherwise interpret it as a short option.  */
       if (!long_only || argv[optind][1] == '-'
 #ifdef GETOPT_COMPAT
-         || argv[optind][0] == '+'
-#endif                         /* GETOPT_COMPAT */
-         || my_index (optstring, *nextchar) == NULL)
-       {
-         if (opterr)
-           {
-             if (argv[optind][1] == '-')
-               /* --option */
-               fprintf (stderr, "%s: unrecognized option `--%s'\n",
-                        argv[0], nextchar);
-             else
-               /* +option or -option */
-               fprintf (stderr, "%s: unrecognized option `%c%s'\n",
-                        argv[0], argv[optind][0], nextchar);
-           }
-         nextchar = (char *) "";
-         optind++;
-         return '?';
-       }
+          || argv[optind][0] == '+'
+#endif                          /* GETOPT_COMPAT */
+          || my_index (optstring, *nextchar) == NULL)
+        {
+          if (opterr)
+            {
+              if (argv[optind][1] == '-')
+                /* --option */
+                fprintf (stderr, "%s: unrecognized option `--%s'\n",
+                         argv[0], nextchar);
+              else
+                /* +option or -option */
+                fprintf (stderr, "%s: unrecognized option `%c%s'\n",
+                         argv[0], argv[optind][0], nextchar);
+            }
+          nextchar = (char *) "";
+          optind++;
+          return '?';
+        }
     }
 
   /* Look at and handle the next option-character.  */
@@ -588,71 +588,71 @@ _getopt_internal (
 
     if (temp == NULL || c == ':')
       {
-       if (opterr)
-         {
+        if (opterr)
+          {
 #if 0
-           if (c < 040 || c >= 0177)
-             fprintf (stderr, "%s: unrecognized option, character code 0%o\n",
-                      argv[0], c);
-           else
-             fprintf (stderr, "%s: unrecognized option `-%c'\n", argv[0], c);
+            if (c < 040 || c >= 0177)
+              fprintf (stderr, "%s: unrecognized option, character code 0%o\n",
+                       argv[0], c);
+            else
+              fprintf (stderr, "%s: unrecognized option `-%c'\n", argv[0], c);
 #else
-           /* 1003.2 specifies the format of this message.  */
-           fprintf (stderr, "%s: illegal option -- %c\n", argv[0], c);
+            /* 1003.2 specifies the format of this message.  */
+            fprintf (stderr, "%s: illegal option -- %c\n", argv[0], c);
 #endif
-         }
-       optopt = c;
-       return '?';
+          }
+        optopt = c;
+        return '?';
       }
     if (temp[1] == ':')
       {
-       if (temp[2] == ':')
-         {
-           /* This is an option that accepts an argument optionally.  */
-           if (*nextchar != '\0')
-             {
-               optarg = nextchar;
-               optind++;
-             }
-           else
-             optarg = 0;
-           nextchar = NULL;
-         }
-       else
-         {
-           /* This is an option that requires an argument.  */
-           if (*nextchar != '\0')
-             {
-               optarg = nextchar;
-               /* If we end this ARGV-element by taking the rest as an arg,
-                  we must advance to the next element now.  */
-               optind++;
-             }
-           else if (optind == argc)
-             {
-               if (opterr)
-                 {
+        if (temp[2] == ':')
+          {
+            /* This is an option that accepts an argument optionally.  */
+            if (*nextchar != '\0')
+              {
+                optarg = nextchar;
+                optind++;
+              }
+            else
+              optarg = 0;
+            nextchar = NULL;
+          }
+        else
+          {
+            /* This is an option that requires an argument.  */
+            if (*nextchar != '\0')
+              {
+                optarg = nextchar;
+                /* If we end this ARGV-element by taking the rest as an arg,
+                   we must advance to the next element now.  */
+                optind++;
+              }
+            else if (optind == argc)
+              {
+                if (opterr)
+                  {
 #if 0
-                   fprintf (stderr, "%s: option `-%c' requires an argument\n",
-                            argv[0], c);
+                    fprintf (stderr, "%s: option `-%c' requires an argument\n",
+                             argv[0], c);
 #else
-                   /* 1003.2 specifies the format of this message.  */
-                   fprintf (stderr, "%s: option requires an argument -- %c\n",
-                            argv[0], c);
+                    /* 1003.2 specifies the format of this message.  */
+                    fprintf (stderr, "%s: option requires an argument -- %c\n",
+                             argv[0], c);
 #endif
-                 }
-               optopt = c;
-               if (optstring[0] == ':')
-                 c = ':';
-               else
-                 c = '?';
-             }
-           else
-             /* We already incremented `optind' once;
-                increment it again when taking next ARGV-elt as argument.  */
-             optarg = argv[optind++];
-           nextchar = NULL;
-         }
+                  }
+                optopt = c;
+                if (optstring[0] == ':')
+                  c = ':';
+                else
+                  c = '?';
+              }
+            else
+              /* We already incremented `optind' once;
+                 increment it again when taking next ARGV-elt as argument.  */
+              optarg = argv[optind++];
+            nextchar = NULL;
+          }
       }
     return c;
   }
@@ -665,12 +665,12 @@ getopt (
      const char *optstring)
 {
   return _getopt_internal (argc, argv, optstring,
-                          (const struct option *) 0,
-                          (int *) 0,
-                          0);
+                           (const struct option *) 0,
+                           (int *) 0,
+                           0);
 }
 
-#endif /* _LIBC or not __GNU_LIBRARY__.  */
+#endif  /* _LIBC or not __GNU_LIBRARY__.  */
 \f
 #ifdef TEST
 
@@ -691,51 +691,51 @@ main (argc, argv)
 
       c = getopt (argc, argv, "abc:d:0123456789");
       if (c == EOF)
-       break;
+        break;
 
       switch (c)
-       {
-       case '0':
-       case '1':
-       case '2':
-       case '3':
-       case '4':
-       case '5':
-       case '6':
-       case '7':
-       case '8':
-       case '9':
-         if (digit_optind != 0 && digit_optind != this_option_optind)
-           printf ("digits occur in two different argv-elements.\n");
-         digit_optind = this_option_optind;
-         printf ("option %c\n", c);
-         break;
-
-       case 'a':
-         printf ("option a\n");
-         break;
-
-       case 'b':
-         printf ("option b\n");
-         break;
-
-       case 'c':
-         printf ("option c with value `%s'\n", optarg);
-         break;
-
-       case '?':
-         break;
-
-       default:
-         printf ("?? getopt returned character code 0%o ??\n", c);
-       }
+        {
+        case '0':
+        case '1':
+        case '2':
+        case '3':
+        case '4':
+        case '5':
+        case '6':
+        case '7':
+        case '8':
+        case '9':
+          if (digit_optind != 0 && digit_optind != this_option_optind)
+            printf ("digits occur in two different argv-elements.\n");
+          digit_optind = this_option_optind;
+          printf ("option %c\n", c);
+          break;
+
+        case 'a':
+          printf ("option a\n");
+          break;
+
+        case 'b':
+          printf ("option b\n");
+          break;
+
+        case 'c':
+          printf ("option c with value `%s'\n", optarg);
+          break;
+
+        case '?':
+          break;
+
+        default:
+          printf ("?? getopt returned character code 0%o ??\n", c);
+        }
     }
 
   if (optind < argc)
     {
       printf ("non-option ARGV-elements: ");
       while (optind < argc)
-       printf ("%s ", argv[optind++]);
+        printf ("%s ", argv[optind++]);
       printf ("\n");
     }