-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Process.Unix: consider executable permission while searching PATH.
- Loading branch information
Showing
9 changed files
with
167 additions
and
4 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetGroups.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
internal static partial class Interop | ||
{ | ||
internal static partial class Sys | ||
{ | ||
internal static unsafe uint[]? GetGroups() | ||
{ | ||
const int InitialGroupsLength = | ||
#if DEBUG | ||
1; | ||
#else | ||
64; | ||
#endif | ||
Span<uint> groups = stackalloc uint[InitialGroupsLength]; | ||
do | ||
{ | ||
int rv; | ||
fixed (uint* pGroups = groups) | ||
{ | ||
rv = Interop.Sys.GetGroups(groups.Length, pGroups); | ||
} | ||
|
||
if (rv >= 0) | ||
{ | ||
// success | ||
return groups.Slice(0, rv).ToArray(); | ||
} | ||
else if (rv == -1 && Interop.Sys.GetLastError() == Interop.Error.EINVAL) | ||
{ | ||
// increase buffer size | ||
groups = new uint[groups.Length * 2]; | ||
} | ||
else | ||
{ | ||
// failure | ||
return null; | ||
} | ||
} | ||
while (true); | ||
} | ||
|
||
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetGroups", SetLastError = true)] | ||
private static extern unsafe int GetGroups(int ngroups, uint* groups); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters