Skip to content

Commit

Permalink
Remove use of fstat and exchanged chmod with fchmod
Browse files Browse the repository at this point in the history
  • Loading branch information
martintc committed Oct 11, 2021
1 parent 7a3cf3f commit 810a316
Showing 1 changed file with 22 additions and 33 deletions.
55 changes: 22 additions & 33 deletions ut_assert/src/uttools.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,11 @@ bool UtMem2BinFile(const void *Memory, const char *Filename, uint32 Length)
FILE * fp;
struct stat dststat;

if ((stat(Filename, &dststat) == 0))
if ((fchmod(fp, dststat.st_mode & ~(S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH)) == 0)
{
if ((chmod(Filename, dststat.st_mode & ~(S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH)) == 0))
{
stat(Filename, &dststat);
if ((fp = fopen(Filename, "w")))
{
fwrite(Memory, Length, 1, fp);
fclose(fp);
return (true);
}
}
fwrite(Memory, Length, 1, fp);
fclose(fp);
return (true);
}
else
{
Expand Down Expand Up @@ -113,31 +106,27 @@ bool UtMem2HexFile(const void *Memory, const char *Filename, uint32 Length)

if ((fp = fopen(Filename, "w")))
{
if (stat(Filename, &dststat) == 0)
if ((fchmod(fp, dststat.st_mode & ~(S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH)) == 0))
{
if((chmod(Filename, dststat.st_mode & ~(S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH)) == 0))
{
stat(Filename, &dststat);
}
}

for (i = 0; i < Length; i += 16)
{
fprintf(fp, " %06lX: ", (unsigned long)i);
for (j = 0; j < 16; j++)
{
if ((i + j) < Length)
fprintf(fp, "%02X ", ((uint8 *)Memory)[i + j]);
else
fprintf(fp, " ");
}
fprintf(fp, " ");
for (j = 0; j < 16; j++)

for (i = 0; i < Length; i += 16)
{
if ((i + j) < Length)
fprintf(fp, "%c", isprint(((uint8 *)Memory)[i + j]) ? ((uint8 *)Memory)[i + j] : '.');
fprintf(fp, " %06lX: ", (unsigned long)i);
for (j = 0; j < 16; j++)
{
if ((i + j) < Length)
fprintf(fp, "%02X ", ((uint8 *)Memory)[i + j]);
else
fprintf(fp, " ");
}
fprintf(fp, " ");
for (j = 0; j < 16; j++)
{
if ((i + j) < Length)
fprintf(fp, "%c", isprint(((uint8 *)Memory)[i + j]) ? ((uint8 *)Memory)[i + j] : '.');
}
fprintf(fp, "\n");
}
fprintf(fp, "\n");
}
fclose(fp);
return (true);
Expand Down

0 comments on commit 810a316

Please sign in to comment.