2 * Copyright 1993-2002 Christopher Seiwald and Perforce Software, Inc.
4 * This file is part of Jam - see jam.c for Copyright information.
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)
22 # include <:sys:stat.h>
25 * filemac.c - manipulate file names and scan directories on macintosh
29 * file_dirscan() - scan a directory for files
30 * file_time() - get timestamp of file, if not done by file_dirscan()
31 * file_archscan() - scan an archive for files
33 * File_dirscan() and file_archscan() call back a caller provided function
34 * for each file found. A flag to this callback function lets file_dirscan()
35 * and file_archscan() indicate that a timestamp is being provided with the
36 * file. If file_dirscan() or file_archscan() do not provide the file's
37 * timestamp, interested parties may later call file_time().
39 * 04/08/94 (seiwald) - Coherent/386 support added.
40 * 12/19/94 (mikem) - solaris string table insanity support
41 * 02/14/95 (seiwald) - parse and build /xxx properly
42 * 05/03/96 (seiwald) - split into pathunix.c
43 * 11/21/96 (peterk) - BEOS does not have Unix-style archives
47 void CopyC2PStr( char const * cstr, StringPtr pstr )
50 for ( len = 0; *cstr && ( len < 255 ); pstr[ ++len ] = *cstr++ );
56 * file_dirscan() - scan a directory for files.
59 void file_dirscan( char * dir, scanback func, void * closure )
63 unsigned char fullPath[ 512 ];
71 /* First enter directory itself. */
73 memset( (char *)&f, '\0', sizeof( f ) );
76 f.f_dir.len = strlen(dir);
79 printf( "scan directory %s\n", dir );
81 /* Special case ":" - enter it */
83 if ( ( f.f_dir.len == 1 ) && ( f.f_dir.ptr[0] == ':' ) )
84 (*func)( closure, dir, 0 /* not stat()'ed */, (time_t)0 );
86 /* Now enter contents of directory */
88 vol.ioNamePtr = volName;
90 if ( PBHGetVolSync( &vol ) )
93 CopyC2PStr( dir, fullPath );
95 if ( FSMakeFSSpec( vol.ioWDVRefNum, vol.ioWDDirID, fullPath, &spec ) )
98 lastInfo.dirInfo.ioVRefNum = spec.vRefNum;
99 lastInfo.dirInfo.ioDrDirID = spec.parID;
100 lastInfo.dirInfo.ioNamePtr = spec.name;
101 lastInfo.dirInfo.ioFDirIndex = 0;
102 lastInfo.dirInfo.ioACUser = 0;
104 if ( PBGetCatInfoSync( &lastInfo ) )
107 if ( !( lastInfo.dirInfo.ioFlAttrib & 0x10 ) )
110 /* ioDrDirID must be reset each time. */
111 spec.parID = lastInfo.dirInfo.ioDrDirID;
113 string_new( filename );
116 lastInfo.dirInfo.ioVRefNum = spec.vRefNum;
117 lastInfo.dirInfo.ioDrDirID = spec.parID;
118 lastInfo.dirInfo.ioNamePtr = fullPath;
119 lastInfo.dirInfo.ioFDirIndex = index++;
121 if ( PBGetCatInfoSync( &lastInfo ) )
124 f.f_base.ptr = (char *)fullPath + 1;
125 f.f_base.len = *fullPath;
127 string_truncate( filename, 0 );
128 path_build( &f, filename, 0 );
129 (*func)( closure, filename->value, 0 /* not stat()'ed */, (time_t)0 );
131 string_free( filename );
136 * file_time() - get timestamp of file, if not done by file_dirscan().
139 int file_time( char * filename, time_t * time )
143 if ( stat( filename, &statbuf ) < 0 )
146 *time = statbuf.st_mtime;
152 int file_is_file( char * filename )
155 if ( stat( filename, &statbuf ) < 0 )
157 return S_ISREG( statbuf.st_mode ) ? 1 : 0;
160 int file_mkdir(char *pathname)
162 return mkdir(pathname, 0766);
167 * file_archscan() - scan an archive for files.
170 void file_archscan( char * archive, scanback func, void * closure )
175 # endif /* macintosh */