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/*
8 * fileos2.c - scan directories and archives on NT
9 *
10 * External routines:
11 *
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
15 *
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().
21 *
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
28 */
29
30# include "jam.h"
31# include "filesys.h"
32# include "pathsys.h"
33
34# ifdef OS_OS2
35
36# include <io.h>
37# include <dos.h>
38
39/*
40 * file_dirscan() - scan a directory for files
41 */
42
43void
44file_dirscan(
45	const char *dir,
46	scanback func,
47	void	*closure )
48{
49	PATHNAME f;
50	char filespec[ MAXJPATH ];
51	char filename[ MAXJPATH ];
52	long handle;
53	int ret;
54	struct _find_t finfo[1];
55
56	/* First enter directory itself */
57
58	memset( (char *)&f, '\0', sizeof( f ) );
59
60	f.f_dir.ptr = dir;
61	f.f_dir.len = strlen(dir);
62
63	dir = *dir ? dir : ".";
64
65 	/* Special case \ or d:\ : enter it */
66
67	strcpy( filespec, dir );
68
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 );
73	else
74	    strcat( filespec, "/" );
75
76	strcat( filespec, "*" );
77
78	/* Now enter contents of directory */
79
80	if( DEBUG_BINDSCAN )
81	    printf( "scan directory %s\n", filespec );
82
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. */
86
87	if( !_dos_findfirst( filespec, _A_NORMAL|_A_RDONLY|_A_SUBDIR, finfo ) )
88	{
89	    do
90	    {
91		f.f_base.ptr = finfo->name;
92		f.f_base.len = strlen( finfo->name );
93
94		path_build( &f, filename, 0 );
95
96		(*func)( closure, filename, 0 /* not stat()'ed */, (time_t)0 );
97	    }
98	    while( !_dos_findnext( finfo ) );
99	}
100
101}
102
103/*
104 * file_time() - get timestamp of file, if not done by file_dirscan()
105 */
106
107int
108file_time(
109	const char *filename,
110	time_t	*time )
111{
112	/* This is called on OS2, not NT.  */
113	/* NT fills in the time in the dirscan. */
114
115	struct stat statbuf;
116
117	if( stat( filename, &statbuf ) < 0 )
118	    return -1;
119
120	*time = statbuf.st_mtime;
121
122	return 0;
123}
124
125void
126file_archscan(
127	const char *archive,
128	scanback func,
129	void	*closure )
130{
131}
132
133# endif /* OS2 */
134
135