2 * Copyright 1993-2002 Christopher Seiwald and Perforce Software, Inc.
4 * This file is part of Jam - see jam.c for Copyright information.
8 * fileos2.c - scan directories and archives on NT
12 * file_dirscan() - scan a directory for files
13 * file_time() - get timestamp of file, if not done by file_dirscan()
14 * file_archscan() - scan an archive for files
16 * File_dirscan() and file_archscan() call back a caller provided function
17 * for each file found. A flag to this callback function lets file_dirscan()
18 * and file_archscan() indicate that a timestamp is being provided with the
19 * file. If file_dirscan() or file_archscan() do not provide the file's
20 * timestamp, interested parties may later call file_time().
22 * 07/10/95 (taylor) Findfirst() returns the first file on NT.
23 * 05/03/96 (seiwald) split apart into pathnt.c
24 * 01/20/00 (seiwald) - Upgraded from K&R to ANSI C
25 * 09/22/00 (seiwald) handle \ and c:\ specially: don't add extra /
26 * 01/08/01 (seiwald) - closure param for file_dirscan/file_archscan
27 * 11/04/02 (seiwald) - const-ing for string literals
40 * file_dirscan() - scan a directory for files
50 char filespec
[ MAXJPATH
];
51 char filename
[ MAXJPATH
];
54 struct _find_t finfo
[1];
56 /* First enter directory itself */
58 memset( (char *)&f
, '\0', sizeof( f
) );
61 f
.f_dir
.len
= strlen(dir
);
63 dir
= *dir
? dir
: ".";
65 /* Special case \ or d:\ : enter it */
67 strcpy( filespec
, dir
);
69 if( f
.f_dir
.len
== 1 && f
.f_dir
.ptr
[0] == '\\' )
70 (*func
)( closure
, dir
, 0 /* not stat()'ed */, (time_t)0 );
71 else if( f
.f_dir
.len
== 3 && f
.f_dir
.ptr
[1] == ':' )
72 (*func
)( closure
, dir
, 0 /* not stat()'ed */, (time_t)0 );
74 strcat( filespec
, "/" );
76 strcat( filespec
, "*" );
78 /* Now enter contents of directory */
81 printf( "scan directory %s\n", filespec
);
83 /* Time info in dos find_t is not very useful. It consists */
84 /* of a separate date and time, and putting them together is */
85 /* not easy. So we leave that to a later stat() call. */
87 if( !_dos_findfirst( filespec
, _A_NORMAL
|_A_RDONLY
|_A_SUBDIR
, finfo
) )
91 f
.f_base
.ptr
= finfo
->name
;
92 f
.f_base
.len
= strlen( finfo
->name
);
94 path_build( &f
, filename
, 0 );
96 (*func
)( closure
, filename
, 0 /* not stat()'ed */, (time_t)0 );
98 while( !_dos_findnext( finfo
) );
104 * file_time() - get timestamp of file, if not done by file_dirscan()
109 const char *filename
,
112 /* This is called on OS2, not NT. */
113 /* NT fills in the time in the dirscan. */
117 if( stat( filename
, &statbuf
) < 0 )
120 *time
= statbuf
.st_mtime
;