glob.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* This code is MKS code ported to Solaris originally with minimum
* modifications so that upgrades from MKS would readily integrate.
* The MKS basis for this modification was:
*
* $Id: glob.c 1.31 1994/04/07 22:50:43 mark
*
* Additional modifications have been made to this code to make it
* 64-bit clean.
*/
/*
* glob, globfree -- POSIX.2 compatible file name expansion routines.
*
* Copyright 1985, 1991 by Mortice Kern Systems Inc. All rights reserved.
*
* Written by Eric Gisin.
*/
#include "lint.h"
#include <stdio.h>
#include <unistd.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>
#include <glob.h>
#include <errno.h>
#include <fnmatch.h>
#define NULLCPP ((char **)0) /* Null char ** */
int (*)(const char *, int), char **);
static int pstrcmp(const void *, const void *);
/*
* Free all space consumed by glob.
*/
void
{
size_t i;
return;
}
/*
* Do filename expansion.
*/
int
{
int rv;
size_t i;
char *path;
if ((flags & GLOB_DOOFFS) == 0)
if (!(flags & GLOB_APPEND)) {
return (GLOB_NOSPACE);
}
return (GLOB_NOSPACE);
if (rv == GLOB_ABORTED) {
/*
* User's error function returned non-zero, or GLOB_ERR was
* set, and we encountered a directory we couldn't search.
*/
return (GLOB_ABORTED);
}
pstrcmp);
}
if (i == 0) {
if (flags & GLOB_NOCHECK)
else
rv = GLOB_NOMATCH;
}
return (rv);
}
/*
* Recursive routine to match glob pattern, and walk directories.
*/
int
{
size_t n;
size_t m;
int expand = 0; /* path has pattern */
char *cp;
struct dirent64 *d;
int namemax;
int err;
for (;;)
case '\0': /* end of source path */
if (expand)
goto Expand;
else {
if (!(flags & GLOB_NOCHECK) ||
return (0);
}
*dp = '\0';
*--dp = '/';
}
return (GLOB_NOSPACE);
}
return (0);
}
/*NOTREACHED*/
case '*':
case '?':
case '[':
case '\\':
++expand;
break;
case '/':
if (expand)
goto Expand;
break;
/* determine directory and open it */
#ifdef NAME_MAX
#else
#endif
== NULL) {
return (GLOB_NOSPACE);
}
return (GLOB_ABORTED);
}
return (0);
}
/* extract pattern component */
return (GLOB_NOSPACE);
}
if (*--sp != '\0')
flags |= GLOB__CHECK;
/* expand path to max. expansion */
return (GLOB_NOSPACE);
}
/* read directory and match entries */
err = 0;
if (d == NULL)
break;
if ((flags&GLOB_NOESCAPE)
continue;
if (err != 0)
break;
}
return (err);
}
/* NOTREACHED */
}
/*
* Comparison routine for two name arguments, called by qsort.
*/
int
{
}
/*
* Add a new matched filename to the glob_t structure, increasing the
* size of that array, as required.
*/
int
{
char *cp;
return (GLOB_NOSPACE);
return (GLOB_NOSPACE);
}
return (0);
}