mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-15 21:24:16 +01:00
feat(MemoryHelper): add NullTerminate
This commit is contained in:
parent
173804cbe1
commit
a4d8b9c45b
1 changed files with 23 additions and 0 deletions
|
|
@ -730,5 +730,28 @@ namespace Dalamud.Memory
|
|||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Utility
|
||||
|
||||
/// <summary>
|
||||
/// Null-terminate a byte array.
|
||||
/// </summary>
|
||||
/// <param name="bytes">The byte array to terminate.</param>
|
||||
/// <returns>The terminated byte array.</returns>
|
||||
public static byte[] NullTerminate(this byte[] bytes)
|
||||
{
|
||||
if (bytes.Length == 0 || bytes[^1] != 0)
|
||||
{
|
||||
var newBytes = new byte[bytes.Length + 1];
|
||||
Array.Copy(bytes, newBytes, bytes.Length);
|
||||
newBytes[^1] = 0;
|
||||
|
||||
return newBytes;
|
||||
}
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue