added Slackware build script
[k8jam.git] / fileos2.c
blob1380c18fe7c37ac05e6ebd7379cc085b1604f918
1 /*
2 * Copyright 1993-2002 Christopher Seiwald and Perforce Software, Inc.
4 * This file is part of Jam - see jam.c for Copyright information.
5 */
7 /*
8 * fileos2.c - scan directories and archives on NT
10 * External routines:
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
30 # include "jam.h"
31 # include "filesys.h"
32 # include "pathsys.h"
34 # ifdef OS_OS2
36 # include <io.h>
37 # include <dos.h>
40 * file_dirscan() - scan a directory for files
43 void
44 file_dirscan(
45 const char *dir,
46 scanback func,
47 void *closure )
49 PATHNAME f;
50 char filespec[ MAXJPATH ];
51 char filename[ MAXJPATH ];
52 long handle;
53 int ret;
54 struct _find_t finfo[1];
56 /* First enter directory itself */
58 memset( (char *)&f, '\0', sizeof( f ) );
60 f.f_dir.ptr = dir;
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 );
73 else
74 strcat( filespec, "/" );
76 strcat( filespec, "*" );
78 /* Now enter contents of directory */
80 if( DEBUG_BINDSCAN )
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()
108 file_time(
109 const char *filename,
110 time_t *time )
112 /* This is called on OS2, not NT. */
113 /* NT fills in the time in the dirscan. */
115 struct stat statbuf;
117 if( stat( filename, &statbuf ) < 0 )
118 return -1;
120 *time = statbuf.st_mtime;
122 return 0;
125 void
126 file_archscan(
127 const char *archive,
128 scanback func,
129 void *closure )
133 # endif /* OS2 */