let IO := requireModule "IO" in let FFI := requireModule "FFI" in let List := requireModule "List" in let Error := requireModule "Error" in let nil? := List.nil? in let Logic := requireModule "Logic" in let Arithmetic := requireModule "Arithmetic" in let Composition := requireModule "Composition" in let String := requireModule "String" in let accumrUntil! := IO.accumrUntil! in let (;) := IO.(;) in let head := List.head in let strcat := String.strcat in let packRecord := FFI.packRecord in let unpackRecord := FFI.unpackRecord in let duplicateRecord! := FFI.duplicateRecord! in let allocateRecord! := FFI.allocateRecord! in let recordSize := FFI.recordSize in let allocateMemory! := FFI.allocateMemory! in let allocatePointer! := FFI.allocatePointer! in let strUntilZero := FFI.strUntilZero in export let toUnicode := \text int count = WideCharToMultiByte(CP_UTF8, 0, source.c_str(), -1, NULL, 0, NULL, NULL); char* result = (char*) GC_MALLOC_ATOMIC(count); if(WideCharToMultiByte(CP_UTF8, 0, source.c_str(), -1, result, count, NULL, NULL) != count) abort(); in export let getDirents! := \name rem "TODO proper error checking (especially bailing out in the middle)"$ getWin32FindDataWSize! [] ;\sz allocateMemory! sz ;\buffer with! (findFirstFileW! (toUnicode (strcat name "/*")) buffer) findClose! \dir accumrUntil! (\v not (snd v)) (\a \b a:(fst b)) [] Builtins.unpackWin32FindDataW! buffer ;\result findNextFileW! dir buffer ;\OK? return! (result, OK?) in