PATH_MAX is not an upper bound on path lengths on Unix. system function return
values should be used to determine behavior, instead of limiting the path length.
MaxName is not used. When used, it should take into account the file system at
that path.
Commit migrated from https://github.com/dotnet/corefx/commit/
385225e78205d9558924e05fa854326e6ee7116f
}
// If that was too small, try increasing large buffer sizes
- // until we get one that works or until we hit MaxPath.
- int maxPath = Interop.Sys.MaxPath;
- if (StackLimit < maxPath)
+ int bufferSize = StackLimit;
+ do
{
- int bufferSize = StackLimit;
- do
+ checked { bufferSize *= 2; }
+ var buf = new byte[bufferSize];
+ fixed (byte* ptr = &buf[0])
{
- checked { bufferSize *= 2; }
- var buf = new byte[Math.Min(bufferSize, maxPath)];
- fixed (byte* ptr = &buf[0])
+ result = GetCwdHelper(ptr, buf.Length);
+ if (result != null)
{
- result = GetCwdHelper(ptr, buf.Length);
- if (result != null)
- {
- return result;
- }
+ return result;
}
}
- while (bufferSize < maxPath);
}
-
- // If we couldn't get the cwd with a MaxPath-sized buffer, something's wrong.
- throw Interop.GetExceptionForIoErrno(new ErrorInfo(Interop.Error.ENAMETOOLONG));
+ while (true);
}
private static unsafe string GetCwdHelper(byte* ptr, int bufferSize)
{
internal static partial class Sys
{
- internal static int DEFAULT_PC_NAME_MAX = 255;
-
internal enum PathConfName : int
{
PC_LINK_MAX = 1,
PC_VDISABLE = 9,
}
- /// <summary>The maximum path length for the system. -1 if it hasn't yet been initialized.</summary>
- private static int s_maxPath = -1;
-
- /// <summary>The maximum name length for the system. -1 if it hasn't yet been initialized.</summary>
- private static int s_maxName = -1;
-
- internal static int MaxPath
- {
- get
- {
- // Benign race condition on cached value
- if (s_maxPath < 0)
- {
- // GetMaximumPath returns a long from PathConf
- // but our callers expect an int so we need to convert.
- long temp = GetMaximumPath();
- if (temp > int.MaxValue)
- s_maxPath = int.MaxValue;
- else
- s_maxPath = Convert.ToInt32(temp);
- }
- return s_maxPath;
- }
- }
-
- internal static int MaxName
- {
- get
- {
- // Benign race condition on cached value
- if (s_maxName < 0)
- {
- int result = PathConf("/", PathConfName.PC_NAME_MAX);
- s_maxName = result >= 0 ? result : DEFAULT_PC_NAME_MAX;
- }
-
- return s_maxName;
- }
- }
-
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_PathConf", SetLastError = true)]
private static extern int PathConf(string path, PathConfName name);
-
- [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetMaximumPath")]
- private static extern long GetMaximumPath();
}
}
private const char InvalidPathChar = '\0';
internal static char[] GetInvalidPathChars() => new char[] { InvalidPathChar };
- internal static readonly int MaxComponentLength = Interop.Sys.MaxName;
-
internal const string ParentDirectoryPrefix = @"../";
internal static int GetRootLength(ReadOnlySpan<char> path)
internal const int UncPrefixLength = 2;
// \\?\UNC\, \\.\UNC\
internal const int UncExtendedPrefixLength = 8;
- internal static readonly int MaxComponentLength = 255;
internal static char[] GetInvalidPathChars() => new char[]
{
return pathconf(path, confValue);
}
-extern "C" int64_t SystemNative_GetMaximumPath()
-{
- int64_t result = pathconf("/", _PC_PATH_MAX);
- if (result == -1)
- {
- result = PATH_MAX;
- }
-
- return result;
-}
-
extern "C" int32_t SystemNative_GetPriority(PriorityWhich which, int32_t who)
{
// GetPriority uses errno 0 to show success to make sure we don't have a stale value
extern "C" int64_t SystemNative_PathConf(const char* path, PathConfName name);
/**
- * Gets the current (or default, on failure) Maximum Path allowed by the system.
- *
- * This is called out explicitly, rather than using PathConf, since the default value changes depending on the platform.
- */
-extern "C" int64_t SystemNative_GetMaximumPath();
-
-/**
* Gets the priority (nice value) of a certain execution group.
*
* Returns the nice value (from -20 to 20) of the group on success; otherwise, returns -1. Unfortunately, -1 is also a