From 99a8536effde198934f1bf88adfec788f5522b71 Mon Sep 17 00:00:00 2001
From: Todd Martin <kj4ntv@gmail.com>
Date: Mon, 11 Oct 2021 08:41:02 -0700
Subject: [PATCH] Get information about file using fstat

Needed for fchmod.
---
 ut_assert/src/uttools.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/ut_assert/src/uttools.c b/ut_assert/src/uttools.c
index 09e02dd75..d94c50418 100644
--- a/ut_assert/src/uttools.c
+++ b/ut_assert/src/uttools.c
@@ -61,6 +61,7 @@ bool UtMem2BinFile(const void *Memory, const char *Filename, uint32 Length)
 
     if (fp = fopen(Filename, "w")) {
         int fd = fileno(fp);
+        fstat(fd, &dststat);
         if ((fchmod(fd, dststat.st_mode & ~(S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH)) == 0))
         {
             fwrite(Memory, Length, 1, fp);
@@ -114,6 +115,7 @@ bool UtMem2HexFile(const void *Memory, const char *Filename, uint32 Length)
     if ((fp = fopen(Filename, "w")))
     {
       int fd = fileno(fp);
+      fstat(fd, &dststat);
         if ((fchmod(fd, dststat.st_mode & ~(S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH)) == 0))
         {