dir.c (200417) | dir.c (201526) |
---|---|
1/*- 2 * Copyright (c) 1988, 1989, 1990, 1993 3 * The Regents of the University of California. All rights reserved. 4 * Copyright (c) 1988, 1989 by Adam de Boor 5 * Copyright (c) 1989 by Berkeley Softworks 6 * All rights reserved. 7 * 8 * This code is derived from software contributed to Berkeley by --- 26 unchanged lines hidden (view full) --- 35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 37 * SUCH DAMAGE. 38 * 39 * @(#)dir.c 8.2 (Berkeley) 1/2/94 40 */ 41 42#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 1988, 1989, 1990, 1993 3 * The Regents of the University of California. All rights reserved. 4 * Copyright (c) 1988, 1989 by Adam de Boor 5 * Copyright (c) 1989 by Berkeley Softworks 6 * All rights reserved. 7 * 8 * This code is derived from software contributed to Berkeley by --- 26 unchanged lines hidden (view full) --- 35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 37 * SUCH DAMAGE. 38 * 39 * @(#)dir.c 8.2 (Berkeley) 1/2/94 40 */ 41 42#include <sys/cdefs.h> |
43__FBSDID("$FreeBSD: head/usr.bin/make/dir.c 200417 2009-12-11 23:20:02Z delphij $"); | 43__FBSDID("$FreeBSD: head/usr.bin/make/dir.c 201526 2010-01-04 18:57:22Z obrien $"); |
44 45/*- 46 * dir.c -- 47 * Directory searching using wildcards and/or normal names... 48 * Used both for source wildcarding in the Makefile and for finding 49 * implicit sources. 50 * 51 * The interface for this module is: --- 4 unchanged lines hidden (view full) --- 56 * 57 * Path_Expand Given a pattern and a path, return a Lst of names 58 * which match the pattern on the search path. 59 * 60 * Path_FindFile Searches for a file on a given search path. 61 * If it exists, the entire path is returned. 62 * Otherwise NULL is returned. 63 * | 44 45/*- 46 * dir.c -- 47 * Directory searching using wildcards and/or normal names... 48 * Used both for source wildcarding in the Makefile and for finding 49 * implicit sources. 50 * 51 * The interface for this module is: --- 4 unchanged lines hidden (view full) --- 56 * 57 * Path_Expand Given a pattern and a path, return a Lst of names 58 * which match the pattern on the search path. 59 * 60 * Path_FindFile Searches for a file on a given search path. 61 * If it exists, the entire path is returned. 62 * Otherwise NULL is returned. 63 * |
64 * Dir_FindHereOrAbove Search for a path in the current directory and 65 * then all the directories above it in turn until 66 * the path is found or we reach the root ("/"). 67 * |
|
64 * Dir_MTime Return the modification time of a node. The file 65 * is searched for along the default search path. 66 * The path and mtime fields of the node are filled in. 67 * 68 * Path_AddDir Add a directory to a search path. 69 * 70 * Dir_MakeFlags Given a search path and a command flag, create 71 * a string with each of the directories in the path --- 6 unchanged lines hidden (view full) --- 78 * search path. 79 * 80 * Dir_ClearPath Resets a search path to the empty list. 81 * 82 * For debugging: 83 * Dir_PrintDirectories Print stats about the directory cache. 84 */ 85 | 68 * Dir_MTime Return the modification time of a node. The file 69 * is searched for along the default search path. 70 * The path and mtime fields of the node are filled in. 71 * 72 * Path_AddDir Add a directory to a search path. 73 * 74 * Dir_MakeFlags Given a search path and a command flag, create 75 * a string with each of the directories in the path --- 6 unchanged lines hidden (view full) --- 82 * search path. 83 * 84 * Dir_ClearPath Resets a search path to the empty list. 85 * 86 * For debugging: 87 * Dir_PrintDirectories Print stats about the directory cache. 88 */ 89 |
86#include <sys/types.h> | 90#include <sys/param.h> |
87#include <sys/stat.h> 88#include <dirent.h> 89#include <err.h> 90#include <stdio.h> 91#include <stdlib.h> 92#include <string.h> 93 94#include "arch.h" --- 751 unchanged lines hidden (view full) --- 846 } else { 847 DEBUGF(DIR, ("failed. Returning NULL\n")); 848 return (NULL); 849 } 850} 851 852/*- 853 *----------------------------------------------------------------------- | 91#include <sys/stat.h> 92#include <dirent.h> 93#include <err.h> 94#include <stdio.h> 95#include <stdlib.h> 96#include <string.h> 97 98#include "arch.h" --- 751 unchanged lines hidden (view full) --- 850 } else { 851 DEBUGF(DIR, ("failed. Returning NULL\n")); 852 return (NULL); 853 } 854} 855 856/*- 857 *----------------------------------------------------------------------- |
858 * Dir_FindHereOrAbove -- 859 * search for a path starting at a given directory and then working 860 * our way up towards the root. 861 * 862 * Input: 863 * here starting directory 864 * search_path the path we are looking for 865 * result the result of a successful search is placed here 866 * rlen the length of the result buffer 867 * (typically MAXPATHLEN + 1) 868 * 869 * Results: 870 * 0 on failure, 1 on success [in which case the found path is put 871 * in the result buffer]. 872 * 873 * Side Effects: 874 *----------------------------------------------------------------------- 875 */ 876int 877Dir_FindHereOrAbove(char *here, char *search_path, char *result, int rlen) 878{ 879 struct stat st; 880 char dirbase[MAXPATHLEN + 1], *db_end; 881 char try[MAXPATHLEN + 1], *try_end; 882 883 /* copy out our starting point */ 884 snprintf(dirbase, sizeof(dirbase), "%s", here); 885 db_end = dirbase + strlen(dirbase); 886 887 /* loop until we determine a result */ 888 while (1) { 889 /* try and stat(2) it ... */ 890 snprintf(try, sizeof(try), "%s/%s", dirbase, search_path); 891 if (stat(try, &st) != -1) { 892 /* 893 * Success! If we found a file, chop off 894 * the filename so we return a directory. 895 */ 896 if ((st.st_mode & S_IFMT) != S_IFDIR) { 897 try_end = try + strlen(try); 898 while (try_end > try && *try_end != '/') 899 try_end--; 900 if (try_end > try) 901 *try_end = 0; /* chop! */ 902 } 903 904 /* 905 * Done! 906 */ 907 snprintf(result, rlen, "%s", try); 908 return(1); 909 } 910 911 /* 912 * Nope, we didn't find it. If we used up dirbase we've 913 * reached the root and failed. 914 */ 915 if (db_end == dirbase) 916 break; /* Failed! */ 917 918 /* 919 * truncate dirbase from the end to move up a dir 920 */ 921 while (db_end > dirbase && *db_end != '/') 922 db_end--; 923 *db_end = 0; /* chop! */ 924 925 } /* while (1) */ 926 927 /* 928 * We failed... 929 */ 930 return(0); 931} 932 933/*- 934 *----------------------------------------------------------------------- |
|
854 * Dir_MTime -- 855 * Find the modification time of the file described by gn along the 856 * search path dirSearchPath. 857 * 858 * Results: 859 * The modification time or 0 if it doesn't exist 860 * 861 * Side Effects: --- 275 unchanged lines hidden --- | 935 * Dir_MTime -- 936 * Find the modification time of the file described by gn along the 937 * search path dirSearchPath. 938 * 939 * Results: 940 * The modification time or 0 if it doesn't exist 941 * 942 * Side Effects: --- 275 unchanged lines hidden --- |