Print this page
Bump Apache dependency to Apache 2


  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  *
  25  * logadm/glob.c -- globbing routines
  26  *
  27  * these routines support two kinds of globs.  first, the
  28  * usual kind of filename globbing, like:
  29  *
  30  *      *.c
  31  *      /var/log/syslog.?
  32  *      log[0-9]*file
  33  *      /var/apache/logs/x*{access,error}_log
  34  *
  35  * this is basically the same syntax that csh supports for globs and
  36  * is provided by the routine glob_glob() which takes a filename and
  37  * returns a list of filenames that match the glob.
  38  *
  39  * the second type is something called a "reglob" which is a pathname
  40  * where the components are regular expressions as described in regex(3c).
  41  * some examples:
  42  *
  43  *      .*\.c
  44  *      /var/log/syslog\..
  45  *      log[0-9].*file
  46  *      /var/log/syslog\.([0-9]+)$0
  47  *
  48  * the last example uses the ()$n form to assign a numeric extension
  49  * on a filename to the "n" value kept by the fn routines with each
  50  * filename (see fn_setn() in fn.c).  logadm uses this mechanism to
  51  * correctly sort lognames when templates containing $n are used.
  52  *
  53  * the routine glob_reglob() is used to expand reglobs.  glob_glob()
  54  * is implemented by expanding the curly braces, converting the globs
  55  * to reglobs, and then passing the work to glob_reglob().
  56  *
  57  * finally, since expanding globs and reglobs requires doing a stat(2)
  58  * on the files, we store the resulting stat information in the filename
  59  * struct (see fn_setstat() in fn.c).
  60  *
  61  * the glob(3c) routines are not used here since they don't support
  62  * braces, and don't support the more powerful reglobs required by logadm.
  63  */
  64 
  65 #pragma ident   "%Z%%M% %I%     %E% SMI"
  66 
  67 #include <stdio.h>
  68 #include <libintl.h>
  69 #include <stdlib.h>
  70 #include <libgen.h>
  71 #include <strings.h>
  72 #include <sys/types.h>
  73 #include <sys/param.h>
  74 #include <sys/stat.h>
  75 #include <dirent.h>
  76 #include "err.h"
  77 #include "fn.h"
  78 #include "glob.h"
  79 
  80 /* forward declarations for functions used internally by this module */
  81 static struct fn_list *glob_debrace(struct fn *fnp);
  82 static struct fn_list *glob_reglob_list(struct fn_list *fnlp);
  83 static boolean_t glob_magic(struct fn *fnp);
  84 
  85 /* expand curly braces (like file{one,two,three}name) */
  86 static struct fn_list *




  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  *
  25  * logadm/glob.c -- globbing routines
  26  *
  27  * these routines support two kinds of globs.  first, the
  28  * usual kind of filename globbing, like:
  29  *
  30  *      *.c
  31  *      /var/log/syslog.?
  32  *      log[0-9]*file
  33  *      /var/apache2/2.2/logs/x*{access,error}_log
  34  *
  35  * this is basically the same syntax that csh supports for globs and
  36  * is provided by the routine glob_glob() which takes a filename and
  37  * returns a list of filenames that match the glob.
  38  *
  39  * the second type is something called a "reglob" which is a pathname
  40  * where the components are regular expressions as described in regex(3c).
  41  * some examples:
  42  *
  43  *      .*\.c
  44  *      /var/log/syslog\..
  45  *      log[0-9].*file
  46  *      /var/log/syslog\.([0-9]+)$0
  47  *
  48  * the last example uses the ()$n form to assign a numeric extension
  49  * on a filename to the "n" value kept by the fn routines with each
  50  * filename (see fn_setn() in fn.c).  logadm uses this mechanism to
  51  * correctly sort lognames when templates containing $n are used.
  52  *
  53  * the routine glob_reglob() is used to expand reglobs.  glob_glob()
  54  * is implemented by expanding the curly braces, converting the globs
  55  * to reglobs, and then passing the work to glob_reglob().
  56  *
  57  * finally, since expanding globs and reglobs requires doing a stat(2)
  58  * on the files, we store the resulting stat information in the filename
  59  * struct (see fn_setstat() in fn.c).
  60  *
  61  * the glob(3c) routines are not used here since they don't support
  62  * braces, and don't support the more powerful reglobs required by logadm.
  63  */
  64 


  65 #include <stdio.h>
  66 #include <libintl.h>
  67 #include <stdlib.h>
  68 #include <libgen.h>
  69 #include <strings.h>
  70 #include <sys/types.h>
  71 #include <sys/param.h>
  72 #include <sys/stat.h>
  73 #include <dirent.h>
  74 #include "err.h"
  75 #include "fn.h"
  76 #include "glob.h"
  77 
  78 /* forward declarations for functions used internally by this module */
  79 static struct fn_list *glob_debrace(struct fn *fnp);
  80 static struct fn_list *glob_reglob_list(struct fn_list *fnlp);
  81 static boolean_t glob_magic(struct fn *fnp);
  82 
  83 /* expand curly braces (like file{one,two,three}name) */
  84 static struct fn_list *