NormFile Refactor

* Updated NormFileGetName to use sbyte* to avoid casting

* Updated design
pull/85/head
mullerj 2024-08-27 22:18:45 -04:00 committed by GitHub
parent e4513ccd53
commit 3ee6345fd0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 7 additions and 12 deletions

View File

@ -97,7 +97,7 @@ class NormApi <<static>> {
+ {static} <<extern>> NormObjectCancel(objectHandle:long) : void + {static} <<extern>> NormObjectCancel(objectHandle:long) : void
+ {static} <<extern>> NormObjectRetain(objectHandle:long) : void + {static} <<extern>> NormObjectRetain(objectHandle:long) : void
+ {static} <<extern>> NormObjectRelease(objectHandle:long) : void + {static} <<extern>> NormObjectRelease(objectHandle:long) : void
+ {static} <<extern>> NormFileGetName(fileHandle:long, nameBuffer:nint, bufferLen:int) : bool + <<unsafe>> {static} <<extern>> NormFileGetName(fileHandle:long, nameBuffer:sbyte*, bufferLen:int) : bool
+ {static} <<extern>> NormFileRename(fileHandle:long, fileName:string) : bool + {static} <<extern>> NormFileRename(fileHandle:long, fileName:string) : bool
+ {static} <<extern>> NormDataAccessData(objectHandle:long) : nint + {static} <<extern>> NormDataAccessData(objectHandle:long) : nint
+ {static} <<extern>> NormObjectGetSender(objectHandle:long) : long + {static} <<extern>> NormObjectGetSender(objectHandle:long) : long

View File

@ -1020,7 +1020,7 @@ namespace Mil.Navy.Nrl.Norm
/// does not refer to an object of type NORM_OBJECT_FILE. /// does not refer to an object of type NORM_OBJECT_FILE.
/// </returns> /// </returns>
[DllImport(NORM_LIBRARY)] [DllImport(NORM_LIBRARY)]
public static extern bool NormFileGetName(long fileHandle, nint nameBuffer, int bufferLen); public unsafe static extern bool NormFileGetName(long fileHandle, sbyte* nameBuffer, int bufferLen);
/// <summary> /// <summary>
/// This function renames the file used to store content for the NORM_OBJECT_FILE transport object specified by /// This function renames the file used to store content for the NORM_OBJECT_FILE transport object specified by

View File

@ -1,7 +1,4 @@
using System.Runtime.InteropServices; namespace Mil.Navy.Nrl.Norm
using System.Text;
namespace Mil.Navy.Nrl.Norm
{ {
/// <summary> /// <summary>
/// A transport object of type NORM_OBJECT_FILE. /// A transport object of type NORM_OBJECT_FILE.
@ -29,16 +26,14 @@ namespace Mil.Navy.Nrl.Norm
{ {
get get
{ {
var buffer = stackalloc byte[FILENAME_MAX]; var buffer = stackalloc sbyte[FILENAME_MAX];
var bufferPtr = (nint)buffer;
if (!NormFileGetName(_handle, bufferPtr, FILENAME_MAX)) if (!NormFileGetName(_handle, buffer, FILENAME_MAX))
{ {
throw new IOException("Failed to get file name"); throw new IOException("Failed to get file name");
} }
var name = Marshal.PtrToStringAnsi(bufferPtr);
return new string(buffer);
return name ?? string.Empty;
} }
} }