Print this page
1097 glob(3c) needs to support non-POSIX options
3341 The sftp command should use the native glob()

Split Close
Expand all
Collapse all
          --- old/usr/src/head/glob.h
          +++ new/usr/src/head/glob.h
↓ open down ↓ 11 lines elided ↑ open up ↑
  12   12   * and limitations under the License.
  13   13   *
  14   14   * When distributing Covered Code, include this CDDL HEADER in each
  15   15   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16   16   * If applicable, add the following below this CDDL HEADER, with the
  17   17   * fields enclosed by brackets "[]" replaced with your own identifying
  18   18   * information: Portions Copyright [yyyy] [name of copyright owner]
  19   19   *
  20   20   * CDDL HEADER END
  21   21   */
       22 +
  22   23  /*
       24 + * Copyright (c) 1989, 1993
       25 + *      The Regents of the University of California.  All rights reserved.
       26 + *
       27 + * This code is derived from software contributed to Berkeley by
       28 + * Guido van Rossum.
       29 + *
       30 + * Redistribution and use in source and binary forms, with or without
       31 + * modification, are permitted provided that the following conditions
       32 + * are met:
       33 + * 1. Redistributions of source code must retain the above copyright
       34 + *    notice, this list of conditions and the following disclaimer.
       35 + * 2. Redistributions in binary form must reproduce the above copyright
       36 + *    notice, this list of conditions and the following disclaimer in the
       37 + *    documentation and/or other materials provided with the distribution.
       38 + * 3. Neither the name of the University nor the names of its contributors
       39 + *    may be used to endorse or promote products derived from this software
       40 + *    without specific prior written permission.
       41 + *
       42 + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
       43 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
       44 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
       45 + * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
       46 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
       47 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
       48 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
       49 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
       50 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
       51 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
       52 + * SUCH DAMAGE.
       53 + *
       54 + *      @(#)glob.h      8.1 (Berkeley) 6/2/93
       55 + */
       56 +
       57 +/*
  23   58   * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
  24   59   * Use is subject to license terms.
       60 + * Copyright (c) 2013 Gary Mills
  25   61   */
  26   62  
  27   63  /*
  28   64   * Copyright 1985, 1992 by Mortice Kern Systems Inc.  All rights reserved.
  29   65   */
  30   66  
  31   67  #ifndef _GLOB_H
  32   68  #define _GLOB_H
  33   69  
  34      -#pragma ident   "%Z%%M% %I%     %E% SMI"
  35      -
  36   70  #include <sys/feature_tests.h>
  37   71  #include <sys/types.h>
       72 +#include <sys/stat.h>
       73 +#include <dirent.h>
  38   74  
  39   75  #ifdef  __cplusplus
  40   76  extern "C" {
  41   77  #endif
  42   78  
  43   79  typedef struct  glob_t  {
  44      -        size_t  gl_pathc;               /* Count of paths matched by pattern */
  45      -        char    **gl_pathv;             /* List of matched pathnames */
  46      -        size_t  gl_offs;                /* # of slots reserved in gl_pathv */
  47      -        /* following are internal to the implementation */
  48      -        char    **gl_pathp;             /* gl_pathv + gl_offs */
  49      -        int     gl_pathn;               /* # of elements allocated */
       80 +        /* Members required by POSIX: */
       81 +        size_t  gl_pathc;       /* Total count of paths matched by pattern */
       82 +        char    **gl_pathv;     /* List of matched pathnames */
       83 +        size_t  gl_offs;        /* # of slots reserved in gl_pathv */
       84 +#if defined(__XOPEN_OR_POSIX) && !defined(__EXTENSIONS__)
       85 +        /* The following are internal to the legacy implementation. */
       86 +        char    **gl_pathp;     /* gl_pathv + gl_offs */
       87 +        int     gl_pathn;       /* # of elements allocated */
       88 +#else /* defined(__XOPEN_OR_POSIX) && !defined(__EXTENSIONS__) */
       89 +        /*
       90 +         * Overlaid non-POSIX extensions, from OpenBSD:
       91 +         * These are used internally for legacy callers but
       92 +         * contain returned values for extended callers.
       93 +         */
       94 +        union {
       95 +        char    **_gl_pathp;    /* gl_pathv + gl_offs */
       96 +        int _gl_matchc;         /* Count of paths matching pattern. */
       97 +        } _gl_pama;
       98 +#define gl_pathp _gl_pama._gl_pathp
       99 +#define gl_matchc _gl_pama._gl_matchc
      100 +        union {
      101 +        int     _gl_pathn;      /* # of elements allocated */
      102 +        int _gl_flags;          /* Copy of flags parameter to glob. */
      103 +        } _gl_pafl;
      104 +#define gl_pathn _gl_pafl._gl_pathn
      105 +#define gl_flags _gl_pafl._gl_flags
      106 +        /* End of legacy glob structure */
      107 +
      108 +        /* Non-POSIX extensions, from OpenBSD: */
      109 +        struct stat **gl_statv; /* Stat entries corresponding to gl_pathv */
      110 +        /*
      111 +         * Alternate filesystem access methods for glob; replacement
      112 +         * versions of closedir(3), readdir(3), opendir(3), stat(2)
      113 +         * and lstat(2).
      114 +         */
      115 +        void (*gl_closedir)(void *);
      116 +        struct dirent *(*gl_readdir)(void *);
      117 +        void *(*gl_opendir)(const char *);
      118 +        int (*gl_lstat)(const char *, struct stat *);
      119 +        int (*gl_stat)(const char *, struct stat *);
      120 +#endif /* defined(__XOPEN_OR_POSIX) && !defined(__EXTENSIONS__) */
  50  121  }       glob_t;
  51  122  
  52  123  /*
  53      - * "flags" argument to glob function.
      124 + * POSIX "flags" argument to glob function.
  54  125   */
  55  126  #define GLOB_ERR        0x0001          /* Don't continue on directory error */
  56  127  #define GLOB_MARK       0x0002          /* Mark directories with trailing / */
  57  128  #define GLOB_NOSORT     0x0004          /* Don't sort pathnames */
  58  129  #define GLOB_NOCHECK    0x0008          /* Return unquoted arg if no match */
  59  130  #define GLOB_DOOFFS     0x0010          /* Ignore gl_offs unless set */
  60  131  #define GLOB_APPEND     0x0020          /* Append to previous glob_t */
  61  132  #define GLOB_NOESCAPE   0x0040          /* Backslashes do not quote M-chars */
      133 +#define GLOB_POSIX      0x007F          /* All POSIX flags */
  62  134  
      135 +#if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
  63  136  /*
      137 + * Non-POSIX "flags" argument to glob function, from OpenBSD.
      138 + */
      139 +#define GLOB_BRACE      0x0080  /* Expand braces ala csh. */
      140 +#define GLOB_MAGCHAR    0x0100  /* Pattern had globbing characters. */
      141 +#define GLOB_NOMAGIC    0x0200  /* GLOB_NOCHECK without magic chars (csh). */
      142 +#define GLOB_QUOTE      0x0400  /* Quote special chars with \. */
      143 +#define GLOB_TILDE      0x0800  /* Expand tilde names from the passwd file. */
      144 +#define GLOB_LIMIT      0x2000  /* Limit pattern match output to ARG_MAX */
      145 +#define GLOB_KEEPSTAT   0x4000  /* Retain stat data for paths in gl_statv. */
      146 +#define GLOB_ALTDIRFUNC 0x8000  /* Use alternately specified directory funcs. */
      147 +#endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
      148 +
      149 +/*
  64  150   * Error returns from "glob"
  65  151   */
  66  152  #define GLOB_NOSYS      (-4)            /* function not supported (XPG4) */
  67  153  #define GLOB_NOMATCH    (-3)            /* Pattern does not match */
  68  154  #define GLOB_NOSPACE    (-2)            /* Not enough memory */
  69  155  #define GLOB_ABORTED    (-1)            /* GLOB_ERR set or errfunc return!=0 */
      156 +#define GLOB_ABEND      GLOB_ABORTED    /* backward compatibility */
  70  157  
  71  158  #if defined(__STDC__)
      159 +
      160 +#ifdef  _GLOB_LIBC
  72  161  extern int glob(const char *_RESTRICT_KYWD, int, int(*)(const char *, int),
  73  162                  glob_t *_RESTRICT_KYWD);
      163 +extern int _glob_ext(const char *_RESTRICT_KYWD, int,
      164 +                    int(*)(const char *, int), glob_t *_RESTRICT_KYWD);
  74  165  extern void globfree(glob_t *);
  75      -#else
      166 +extern void _globfree_ext(glob_t *);
      167 +#else /* _GLOB_LIBC */
      168 +#ifdef __PRAGMA_REDEFINE_EXTNAME
      169 +#pragma redefine_extname        glob    _glob_ext
      170 +#pragma redefine_extname        globfree        _globfree_ext
      171 +extern int glob(const char *_RESTRICT_KYWD, int, int(*)(const char *, int),
      172 +                glob_t *_RESTRICT_KYWD);
      173 +extern void globfree(glob_t *);
      174 +#else /* __PRAGMA_REDEFINE_EXTNAME */
      175 +extern int _glob_ext(const char *_RESTRICT_KYWD, int,
      176 +                    int(*)(const char *, int), glob_t *_RESTRICT_KYWD);
      177 +extern void _globfree_ext(glob_t *);
      178 +#define glob    _glob_ext
      179 +#define globfree        _globfree_ext
      180 +#endif /* __PRAGMA_REDEFINE_EXTNAME */
      181 +#endif /* _GLOB_LIBC */
      182 +
      183 +#else /* __STDC__ */
      184 +
      185 +#ifdef  _GLOB_LIBC
  76  186  extern int glob();
      187 +extern int _glob_ext();
  77  188  extern void globfree();
  78      -#endif
      189 +extern void _globfree_ext();
      190 +#else /* _GLOB_LIBC */
      191 +#ifdef __PRAGMA_REDEFINE_EXTNAME
      192 +#pragma redefine_extname        glob    _glob_ext
      193 +#pragma redefine_extname        globfree        _globfree_ext
      194 +extern int glob();
      195 +extern void globfree();
      196 +#else /* __PRAGMA_REDEFINE_EXTNAME */
      197 +extern int _glob_ext();
      198 +extern void _globfree_ext();
      199 +#define glob    _glob_ext
      200 +#define globfree        _globfree_ext
      201 +#endif /* __PRAGMA_REDEFINE_EXTNAME */
      202 +#endif /* _GLOB_LIBC */
  79  203  
      204 +
      205 +#endif /* __STDC__ */
      206 +
  80  207  #ifdef  __cplusplus
  81  208  }
  82  209  #endif
  83  210  
  84  211  #endif  /* _GLOB_H */
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX