1 | /* |
---|
2 | * Copyright 1993-2002 Christopher Seiwald and Perforce Software, Inc. |
---|
3 | * |
---|
4 | * This file is part of Jam - see jam.c for Copyright information. |
---|
5 | */ |
---|
6 | |
---|
7 | /* This file is ALSO: |
---|
8 | * Copyright 2001-2004 David Abrahams. |
---|
9 | * Distributed under the Boost Software License, Version 1.0. |
---|
10 | * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) |
---|
11 | */ |
---|
12 | |
---|
13 | # include "jam.h" |
---|
14 | # include "filesys.h" |
---|
15 | # include "pathsys.h" |
---|
16 | |
---|
17 | /* note that we use "fileunix.c" when compiling with EMX on OS/2 */ |
---|
18 | # if defined(OS_OS2) && !defined(__EMX__) |
---|
19 | |
---|
20 | # include <io.h> |
---|
21 | # include <dos.h> |
---|
22 | |
---|
23 | /* |
---|
24 | * fileos2.c - scan directories and archives on NT |
---|
25 | * |
---|
26 | * External routines: |
---|
27 | * |
---|
28 | * file_dirscan() - scan a directory for files |
---|
29 | * file_time() - get timestamp of file, if not done by file_dirscan() |
---|
30 | * file_archscan() - scan an archive for files |
---|
31 | * |
---|
32 | * File_dirscan() and file_archscan() call back a caller provided function |
---|
33 | * for each file found. A flag to this callback function lets file_dirscan() |
---|
34 | * and file_archscan() indicate that a timestamp is being provided with the |
---|
35 | * file. If file_dirscan() or file_archscan() do not provide the file's |
---|
36 | * timestamp, interested parties may later call file_time(). |
---|
37 | * |
---|
38 | * 07/10/95 (taylor) Findfirst() returns the first file on NT. |
---|
39 | * 05/03/96 (seiwald) split apart into pathnt.c |
---|
40 | * 09/22/00 (seiwald) handle \ and c:\ specially: don't add extra / |
---|
41 | */ |
---|
42 | |
---|
43 | /* |
---|
44 | * file_dirscan() - scan a directory for files |
---|
45 | */ |
---|
46 | |
---|
47 | void |
---|
48 | file_dirscan( |
---|
49 | char *dir, |
---|
50 | scanback func, |
---|
51 | void *closure ) |
---|
52 | { |
---|
53 | PATHNAME f; |
---|
54 | string filespec[1]; |
---|
55 | long handle; |
---|
56 | int ret; |
---|
57 | struct _find_t finfo[1]; |
---|
58 | |
---|
59 | /* First enter directory itself */ |
---|
60 | |
---|
61 | memset( (char *)&f, '\0', sizeof( f ) ); |
---|
62 | |
---|
63 | f.f_dir.ptr = dir; |
---|
64 | f.f_dir.len = strlen(dir); |
---|
65 | |
---|
66 | dir = *dir ? dir : "."; |
---|
67 | |
---|
68 | /* Special case \ or d:\ : enter it */ |
---|
69 | string_copy( filespec, dir ); |
---|
70 | |
---|
71 | if( f.f_dir.len == 1 && f.f_dir.ptr[0] == '\\' ) |
---|
72 | (*func)( closure, dir, 0 /* not stat()'ed */, (time_t)0 ); |
---|
73 | else if( f.f_dir.len == 3 && f.f_dir.ptr[1] == ':' ) |
---|
74 | (*func)( closure, dir, 0 /* not stat()'ed */, (time_t)0 ); |
---|
75 | else |
---|
76 | string_push_back( filespec, '/' ); |
---|
77 | |
---|
78 | string_push_back( filespec, '*' ); |
---|
79 | |
---|
80 | /* Now enter contents of directory */ |
---|
81 | |
---|
82 | if( DEBUG_BINDSCAN ) |
---|
83 | printf( "scan directory %s\n", filespec->value ); |
---|
84 | |
---|
85 | /* Time info in dos find_t is not very useful. It consists */ |
---|
86 | /* of a separate date and time, and putting them together is */ |
---|
87 | /* not easy. So we leave that to a later stat() call. */ |
---|
88 | |
---|
89 | if( !_dos_findfirst( filespec->value, _A_NORMAL|_A_RDONLY|_A_SUBDIR, finfo ) ) |
---|
90 | { |
---|
91 | string filename[1]; |
---|
92 | string_new( filename ); |
---|
93 | do |
---|
94 | { |
---|
95 | |
---|
96 | f.f_base.ptr = finfo->name; |
---|
97 | f.f_base.len = strlen( finfo->name ); |
---|
98 | |
---|
99 | string_truncate( filename, 0 ); |
---|
100 | path_build( &f, filename, 0 ); |
---|
101 | (*func)( closure, filename->value, 0 /* not stat()'ed */, (time_t)0 ); |
---|
102 | } |
---|
103 | while( !_dos_findnext( finfo ) ); |
---|
104 | string_free( filename ); |
---|
105 | } |
---|
106 | } |
---|
107 | |
---|
108 | /* |
---|
109 | * file_time() - get timestamp of file, if not done by file_dirscan() |
---|
110 | */ |
---|
111 | |
---|
112 | int |
---|
113 | file_time( |
---|
114 | char *filename, |
---|
115 | time_t *time ) |
---|
116 | { |
---|
117 | /* This is called on OS2, not NT. */ |
---|
118 | /* NT fills in the time in the dirscan. */ |
---|
119 | |
---|
120 | struct stat statbuf; |
---|
121 | |
---|
122 | if( stat( filename, &statbuf ) < 0 ) |
---|
123 | return -1; |
---|
124 | |
---|
125 | *time = statbuf.st_mtime; |
---|
126 | |
---|
127 | return 0; |
---|
128 | } |
---|
129 | |
---|
130 | void |
---|
131 | file_archscan( |
---|
132 | char *archive, |
---|
133 | scanback func, |
---|
134 | void *closure ) |
---|
135 | { |
---|
136 | } |
---|
137 | |
---|
138 | # endif /* OS2 && !__EMX__ */ |
---|
139 | |
---|