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;
88 if (i >= num_new_files) {
90 myErr = FSGetCatalogInfoBulk(iterator, 256, &num_new_files, NULL, kFSCatInfoNone, NULL, refs, NULL, NULL);
93 return 1; // The last file
96 FSRefMakePath (refs + i, (unsigned char *) path, 255);
97 for (matchingType = p; *matchingType && strnicmp(matchingType, search_str, strlen(search_str)); matchingType++) {}
101 strncpy(ffstruct->name, p, 12);
102 return 0; // Found one
107 int FileFindNext(FILEFINDSTRUCT *ffstruct)
112 char path[_MAX_PATH];
113 char *p = path + path_len;
116 if (i >= num_new_files) {
118 myErr = FSGetCatalogInfoBulk(iterator, 256, &num_new_files, NULL, kFSCatInfoNone, NULL, refs, NULL, NULL);
121 return 1; // The last file
124 FSRefMakePath (refs + i, (unsigned char *) path, 255);
125 for (matchingType = p; *matchingType && strnicmp(matchingType, type, strlen(type)); matchingType++) {}
129 strncpy(ffstruct->name, p, 12);
130 return 0; // Found one
135 int FileFindClose(void)
138 if (FSCloseIterator(iterator) != noErr)