Skip to content

Commit

Permalink
Update to work with 64 bit file sizes
Browse files Browse the repository at this point in the history
Updated the file information printing routines to account for the fact
that file sizes are now 64 bit, taking into account that Amiga OS has
no support for this.
  • Loading branch information
Colin Ward authored and hitman-codehq committed Nov 23, 2023
1 parent 8980cd5 commit 16dc38e
Showing 1 changed file with 30 additions and 5 deletions.
35 changes: 30 additions & 5 deletions ls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ static const struct Resident g_oROMTag __attribute__((used)) =

#define PRINT_DIR printf("%c0;33;40mDir", 0x9b);
#define PRINT_LINK_PREFIX printf("%c0;34;40m", 0x9b);
#define PRINT_LINK printf("%d", a_poEntry->iSize);
#define PRINT_LINK printf("%d", (int) a_poEntry->iSize);
#define PRINT_NAME printf("%s%c0;31;40m\n", a_poEntry->iName, 0x9b);

#else /* ! __amigaos4__ */
Expand Down Expand Up @@ -77,7 +77,19 @@ static void PrintDetails(const TEntry *a_poEntry)
}
else
{
Length = printf("%d", a_poEntry->iSize);
/* Amiga OS has no support for the %lld format specifier, so we have no choice but to just */
/* cast the 64 bit value to an integer and hope for the best */

#ifdef __amigaos__

Length = printf("%d", (int) a_poEntry->iSize);

#else /* ! __amigaos__ */

Length = printf("%lld", a_poEntry->iSize);

#endif /* ! __amigaos__ */

}

/* Print a number of spaces after the entry's type or size, ensuring that we don't go into an */
Expand Down Expand Up @@ -135,7 +147,7 @@ int main(int a_iArgC, char *a_ppcArgV[])
{
char Char;
int Index, NumEntries, NumFiles, NumLines, RetVal;
unsigned int TotalSize;
TInt64 TotalSize;
enum TDirSortOrder SortOrder;
RDir Dir;
TEntryArray *DirEntries;
Expand Down Expand Up @@ -212,8 +224,9 @@ int main(int a_iArgC, char *a_ppcArgV[])
/* Loop around and display the entries in the directory, keeping track of the */
/* # of files found and their total size */

NumFiles = NumLines = TotalSize = 0;
NumFiles = NumLines = 0;
NumEntries = DirEntries->Count();
TotalSize = 0;

for (Index = 0; Index < NumEntries; ++Index)
{
Expand Down Expand Up @@ -274,7 +287,19 @@ int main(int a_iArgC, char *a_ppcArgV[])

if (Index == NumEntries)
{
printf("%d Files - %d bytes used Bro!\n", NumFiles, TotalSize);
/* Amiga OS has no support for the %lld format specifier, so we have no choice but to just */
/* cast the 64 bit value to an integer and hope for the best */

#ifdef __amigaos__

printf("%d Files - %d bytes used Bro!\n", NumFiles, (int) TotalSize);

#else /* ! __amigaos__ */

printf("%d Files - %lld bytes used Bro!\n", NumFiles, TotalSize);

#endif /* ! __amigaos__ */

}
}
else
Expand Down

0 comments on commit 16dc38e

Please sign in to comment.