/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (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 2003 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* files.c
*
* Various file related routines:
* Figure out if file exists
* Wildcard resolution for directory reader
* Directory reader
*/
/*
* Included files
*/
#include <dirent.h> /* opendir() */
#include <errno.h> /* errno */
#include <libintl.h>
/*
* Defined macros
*/
/*
* typedefs & structs
*/
/*
* Static variables
*/
/*
* File table of contents
*/
/*
* exists(target)
*
* Figure out the timestamp for one target.
*
* Return value:
* The time the target was created
*
* Parameters:
* target The target to check
*
* Global variables used:
* debug_level Should we trace the stat call?
* recursion_level Used for tracing
* vpath_defined Was the variable VPATH defined in environment?
*/
{
register int result;
/* We cache stat information. */
}
/*
* If the target is a member, we have to extract the time
* from the archive.
*/
return read_archive(target);
}
if (debug_level > 1) {
(void) printf("%*sstat(%s)\n",
"",
}
/*
* If the file is a symbolic link, we remember that
* and then we get the status for the refd file.
*/
} else {
}
if (result < 0) {
/* azv, fixing bug 1262942, VPATH works with a leaf name
* but not a directory name.
*/
/* BID_1214655 */
/* azv */
// return vpath_exists(target);
}
} else {
/* Save all the information we need about the file */
} else {
/* BID_1129806 */
/* vis@nbsp.nsk.su */
}
}
if ((target->colon_splits > 0) &&
}
}
/*
* set_target_stat( target, buf)
*
* Called by exists() to set some stat fields in the Name structure
* to those read by the stat_vroot() call (from disk).
*
* Parameters:
* target The target whose stat field is set
* buf stat values (on disk) of the file
* represented by target.
*/
void
{
} else {
/* BID_1129806 */
/* vis@nbsp.nsk.su */
}
}
/*
* vpath_exists(target)
*
* Called if exists() discovers that there is a VPATH defined.
* This function stats the VPATH translation of the target.
*
* Return value:
* The time the target was created
*
* Parameters:
* target The target to check
*
* Global variables used:
* vpath_name The Name "VPATH", used to get macro value
*/
static timestruc_t&
{
wchar_t *vpath;
wchar_t *name_p;
/*
* To avoid recursive search through VPATH when exists(alias) is called
*/
vpath_defined = false;
while ((*vpath != (int) colon_char) &&
}
*name_p++ = (int) slash_char;
target->has_vpath_alias_prop = true;
vpath_defined = true;
}
vpath++;
}
}
/*
* Restore vpath_defined
*/
vpath_defined = true;
}
/*
* read_dir(dir, pattern, line, library)
*
* Used to enter the contents of directories into makes namespace.
* Presence of a file is important when scanning for implicit rules.
* read_dir() is also used to expand wildcards in dependency lists.
*
* Return value:
* Non-0 if we found files to match the pattern
*
* Parameters:
* dir Path to the directory to read
* pattern Pattern for that files should match or NULL
* line When we scan using a pattern we enter files
* we find as dependencies for this line
* library If we scan for "lib.a(<wildcard-member>)"
*
* Global variables used:
* debug_level Should we trace the dir reading?
* dot The Name ".", compared against
* sccs_dir_path The path to the SCCS dir (from PROJECTDIR)
* vpath_defined Was the variable VPATH defined in environment?
* vpath_name The Name "VPATH", use to get macro value
*/
int
{
wchar_t *plain_file_name_p;
int m_local_dependency=0;
wchar_t *p;
int result = 0;
return 0;
}
/* A directory is only read once unless we need to expand wildcards. */
if (dir->has_read_dir) {
return 0;
}
dir->has_read_dir = true;
}
/* Check if VPATH is active and setup list if it is. */
}
/*
* Prepare the string where we build the full name of the
* files in the directory.
*/
}
/* Open the directory. */
return 0;
}
/* Read all the directory entries. */
/* We ignore "." and ".." */
continue;
}
/*
* Build the full name of the file using whatever
* path supplied to the function.
*/
/*
* If we are expanding a wildcard pattern, we
* enter the file as a dependency for the target.
*/
if (debug_level > 0){
}
result++;
} else {
/*
* If the file has an SCCS/s. file,
* we will detect that later on.
*/
/*
* If this is an s. file, we also enter it as if it
* existed in the plain directory.
*/
/*
* Enter the s. file as a dependency for the
* plain file.
*/
if (debug_level > 0) {
}
result++;
}
}
}
}
vpath++;
}
p = vpath;
while ((*vpath != (int) colon_char) &&
vpath++;
}
if (vpath > p) {
goto vpath_loop;
}
}
/*
* look into SCCS directory only if it's not svr4. For svr4 dont do that.
*/
/*
* Now read the SCCS directory.
* Files in the SCSC directory are considered to be part of the set of
* files in the plain directory. They are also entered in their own right.
* Prepare the string where we build the true name of the SCCS files.
*/
(void) wcsncpy(plain_file_name,
file_name_p - file_name);
if(!svr4) {
if (sccs_dir_path != NULL) {
wchar_t tmp_wchar;
if (file_name_p - file_name > 0) {
tmp_wchar = *file_name_p;
*file_name_p = 0;
*file_name_p = tmp_wchar;
} else {
}
} else {
}
} else {
}
/* Internalize the constructed SCCS dir name. */
/* Just give up if the directory file doesnt exist. */
return result;
}
/* Open the directory. */
return result;
}
continue;
}
/* Construct and internalize the true name of the SCCS file. */
/*
* If this is an s. file, we also enter it as if it
* existed in the plain directory.
*/
/* if sccs dependency is already set,skip */
if(plain_file->prop) {
goto try_pattern;
}
}
}
/*
* Enter the s. file as a dependency for the
* plain file.
*/
if (debug_level > 0) {
}
result++;
}
}
}
return result;
}
/*
* enter_file_name(name_string, library)
*
* Helper function for read_dir().
*
* Return value:
* The Name that was entered
*
* Parameters:
* name_string Name of the file we want to enter
* library The library it is a member of, if any
*
* Global variables used:
*/
static Name
{
return name;
}
return name;
}
/*
* star_match(string, pattern)
*
* This is a regular shell type wildcard pattern matcher
* It is used when xpanding wildcards in dependency lists
*
* Return value:
* Indication if the string matched the pattern
*
* Parameters:
* string String to match
* pattern Pattern to match it against
*
* Global variables used:
*/
static Boolean
{
register int pattern_ch;
switch (*pattern) {
case 0:
return succeeded;
case bracketleft_char:
case question_char:
case asterisk_char:
while (*string) {
return succeeded;
}
}
break;
default:
pattern_ch = (int) *pattern++;
while (*string) {
if ((*string++ == pattern_ch) &&
return succeeded;
}
}
break;
}
return failed;
}
/*
* amatch(string, pattern)
*
* Helper function for shell pattern matching
*
* Return value:
* Indication if the string matched the pattern
*
* Parameters:
* string String to match
* pattern Pattern to match it against
*
* Global variables used:
*/
static Boolean
{
register long lower_bound;
register long string_ch;
register long pattern_ch;
register int k;
top:
lower_bound = 017777777777;
switch (pattern_ch = *pattern) {
case bracketleft_char:
k = 0;
while ((pattern_ch = *++pattern) != 0) {
switch (pattern_ch) {
case bracketright_char:
if (!k) {
return failed;
}
string++;
pattern++;
goto top;
case hyphen_char:
k |= (lower_bound <= string_ch) &&
(string_ch <=
default:
if (string_ch ==
(lower_bound = pattern_ch)) {
k++;
}
}
}
return failed;
case asterisk_char:
case 0:
case question_char:
if (string_ch == 0) {
return failed;
}
break;
default:
if (pattern_ch != string_ch) {
return failed;
}
break;
}
}
/* NOTREACHED */
}