DIR

DIR

#Overview

name: DIR

This variable is created as a Console Variable (cvar).

It is referenced in 4 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of DIR is to represent a directory stream in the Unreal Engine’s file system operations, particularly for cross-platform compatibility and low-level file system access.

DIR is primarily used in the core file system and platform-specific modules of Unreal Engine 5. Based on the callsites, it’s utilized in the following areas:

  1. UnrealBuildAccelerator (UBA) for file system operations on POSIX systems
  2. iOS platform-specific file operations
  3. Engine’s core file system functionality

The value of this variable is typically set by system calls like opendir() or fdopendir(), which are often wrapped or intercepted by Unreal Engine’s custom implementations for cross-platform compatibility and performance optimization.

DIR interacts with other file system-related functions and variables, such as opendir, fdopendir, and platform-specific path conversion functions like ConvertToIOSPath.

Developers should be aware that:

  1. DIR is a low-level construct and should be used carefully to ensure cross-platform compatibility.
  2. It’s often wrapped or intercepted by UE5’s custom implementations, so direct use might bypass engine-specific optimizations or functionalities.
  3. Different platforms may have varying implementations or limitations regarding DIR usage.

Best practices when using DIR include:

  1. Prefer using UE5’s high-level file system APIs when possible, rather than directly manipulating DIR.
  2. When low-level access is necessary, use UE5’s platform-specific wrappers or utilities to ensure consistent behavior across different platforms.
  3. Always close directory streams properly to avoid resource leaks.
  4. Be mindful of path normalization and conversion, especially when working with platform-specific code.
  5. Consider using UE5’s abstraction layers for file system operations to maintain better compatibility and easier maintenance across different platforms.

#References in C++ code

#Callsites

This variable is referenced in the following C++ source code:

#Loc: <Workspace>/Engine/Source/Programs/UnrealBuildAccelerator/Detours/Private/PosixOS/UbaDetoursFunctionsPosix.cpp:992

Scope (from outer to inner):

file
function     UBA_EXPORT DIR* UBA_WRAPPER

Source code excerpt:

}

UBA_EXPORT DIR* UBA_WRAPPER(opendir)(const char* name)
{
	UBA_INIT_DETOUR(opendir, name);
	StringBuffer<> dirName;
	FixPath(dirName, name);

	DIR* res = TRUE_WRAPPER(opendir)(dirName.data);

#Loc: <Workspace>/Engine/Source/Programs/UnrealBuildAccelerator/Detours/Private/PosixOS/UbaDetoursFunctionsPosix.cpp:1056

Scope (from outer to inner):

file
function     UBA_EXPORT DIR* UBA_WRAPPER

Source code excerpt:

}

UBA_EXPORT DIR* UBA_WRAPPER(fdopendir)(int fd)
{
	UBA_INIT_DETOUR(fdopendir, fd);
	UBA_ASSERTF(false, "fdopendir");
	DEBUG_LOG_TRUE("fdopendir", "(%i)", fd);
	return TRUE_WRAPPER(fdopendir)(fd);
}

#Loc: <Workspace>/Engine/Source/Runtime/Core/Private/IOS/IOSPlatformFile.cpp:1013

Scope: file

Source code excerpt:

	FString NormalizedDirectory = NormalizeFilename(Directory);
	// If Directory is an empty string, assume that we want to iterate Binaries/Mac (current dir), but because we're an app bundle, iterate bundle's Contents/Frameworks instead
	DIR* Handle = opendir(Directory[0] ? TCHAR_TO_UTF8(*ConvertToIOSPath(NormalizedDirectory, false, false)) : FrameworksPath);
	if(!Handle)
	{
		// look in the private write file path if it's not in the read file path
		Handle = opendir(Directory[0] ? TCHAR_TO_UTF8(*ConvertToIOSPath(NormalizedDirectory, true, false)) : FrameworksPath);
		
		if(!Handle)

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/UnrealEngine.cpp:5180

Scope: file

Source code excerpt:

		return HandleTestslateGameUICommand( Cmd, Ar );
	}
	else if( FParse::Command(&Cmd,TEXT("DIR")) )		// DIR [path\pattern]
	{
		return HandleDirCommand( Cmd, Ar );
	}
	else if( FParse::Command(&Cmd,TEXT("TRACKPARTICLERENDERINGSTATS")) )
	{
		return HandleTrackParticleRenderingStatsCommand( Cmd, Ar );