5 * Created by Chris Taylor on Tue Jun 22 2004.
20 extern void macify_posix_path(char *posix_path, char *mac_path);
22 #include <CoreServices/CoreServices.h>
32 ItemCount num_new_files;
37 int FileFindFirst(char *search_str, FILEFINDSTRUCT *ffstruct)
43 for (path_len = 0; *search_str && *search_str != '*'; path_len ++)
44 path[path_len] = *search_str++;
46 if (*search_str == '*')
48 strcpy(type, search_str);
51 // Convert the search directory to an FSRef in a way that OS 9 can handle
56 macify_posix_path(path, path);
57 CopyCStringToPascal(path, pascalPath);
58 if (FSMakeFSSpec(0, 0, pascalPath, &parentSpec) != noErr)
60 if (FSpMakeFSRef(&parentSpec, &parent) != noErr)
64 // "This function, though available through Carbon on Mac OS 8 and 9, is only implemented on Mac OS X."
65 if ((myErr = FSPathMakeRef((unsigned char const *) (path_len? path : "."), &parent, NULL)) != noErr)
68 if (FSRefMakePath(&parent, (unsigned char *) path, _MAX_PATH) != noErr) // Get the full path, to get the length
70 path_len = strlen(path)
76 if (FSOpenIterator(&parent, kFSIterateFlat, &iterator) != noErr)
79 MALLOC(refs, FSRef, 256);
81 myErr = FSGetCatalogInfoBulk(iterator, 256, &num_new_files, NULL, kFSCatInfoNone, NULL, refs, NULL, NULL);
85 char *p = path + path_len;
87 if (i >= num_new_files) {
89 myErr = FSGetCatalogInfoBulk(iterator, 256, &num_new_files, NULL, kFSCatInfoNone, NULL, refs, NULL, NULL);
92 return 1; // The last file
95 FSRefMakePath (refs + i, (unsigned char *) path, 255);
98 if (!stricmp(p + strlen(p) - strlen(search_str), search_str)) {
99 strncpy(ffstruct->name, p, 256);
100 return 0; // Found one
105 int FileFindNext(FILEFINDSTRUCT *ffstruct)
110 char path[_MAX_PATH];
111 char *p = path + path_len;
113 if (i >= num_new_files) {
115 myErr = FSGetCatalogInfoBulk(iterator, 256, &num_new_files, NULL, kFSCatInfoNone, NULL, refs, NULL, NULL);
118 return 1; // The last file
121 FSRefMakePath (refs + i, (unsigned char *) path, 255);
124 if (!stricmp(p + strlen(p) - strlen(type), type)) {
125 strncpy(ffstruct->name, p, 256);
126 return 0; // Found one
131 int FileFindClose(void)
134 if (FSCloseIterator(iterator) != noErr)