sdlGlobDirectory function

Pointer<Pointer<Int8>> sdlGlobDirectory(
  1. String? path,
  2. String? pattern,
  3. int flags,
  4. Pointer<Int32> count,
)

Enumerate a directory tree, filtered by pattern, and return a list.

Files are filtered out if they don't match the string in pattern, which may contain wildcard characters '' (match everything) and '?' (match one character). If pattern is NULL, no filtering is done and all results are returned. Subdirectories are permitted, and are specified with a path separator of '/'. Wildcard characters '' and '?' never match a path separator.

flags may be set to SDL_GLOB_CASEINSENSITIVE to make the pattern matching case-insensitive.

The returned array is always NULL-terminated, for your iterating convenience, but if count is non-NULL, on return it will contain the number of items in the array, not counting the NULL terminator.

\param path the path of the directory to enumerate. \param pattern the pattern that files in the directory must match. Can be NULL. \param flags SDL_GLOB_* bitflags that affect this search. \param count on return, will be set to the number of items in the returned array. Can be NULL. \returns an array of strings on success or NULL on failure; call SDL_GetError() for more information. This is a single allocation that should be freed with SDL_free() when it is no longer needed.

\threadsafety It is safe to call this function from any thread.

\since This function is available since SDL 3.1.3.

extern SDL_DECLSPEC char ** SDLCALL SDL_GlobDirectory(const char *path, const char *pattern, SDL_GlobFlags flags, int *count)

Implementation

Pointer<Pointer<Int8>> sdlGlobDirectory(
    String? path, String? pattern, int flags, Pointer<Int32> count) {
  final sdlGlobDirectoryLookupFunction = libSdl3.lookupFunction<
      Pointer<Pointer<Int8>> Function(Pointer<Utf8> path, Pointer<Utf8> pattern,
          Uint32 flags, Pointer<Int32> count),
      Pointer<Pointer<Int8>> Function(Pointer<Utf8> path, Pointer<Utf8> pattern,
          int flags, Pointer<Int32> count)>('SDL_GlobDirectory');
  final pathPointer = path != null ? path.toNativeUtf8() : nullptr;
  final patternPointer = pattern != null ? pattern.toNativeUtf8() : nullptr;
  final result =
      sdlGlobDirectoryLookupFunction(pathPointer, patternPointer, flags, count);
  calloc.free(pathPointer);
  calloc.free(patternPointer);
  return result;
}