SDCardUtil: Convert return type of write_* functions to bool

Converts them from 0 == success, 1 == failure to using the built-in
standard bool. Also while we're at it, const qualify write_sector's
"sector" parameter, since nothing in the function modifies the data
being pointed to.
This commit is contained in:
Lioncash 2018-05-11 08:29:36 -04:00
parent 5fc18aa639
commit c26de8107d
No known key found for this signature in database
GPG Key ID: 4E3C3CC1031BA9C7

View File

@ -177,12 +177,12 @@ static void fat_init(u8* fat)
POKEW(fat + 8, 0x0fffffff); /* End of cluster chain for root dir */ POKEW(fat + 8, 0x0fffffff); /* End of cluster chain for root dir */
} }
static unsigned int write_sector(FILE* file, u8* sector) static bool write_sector(FILE* file, const u8* sector)
{ {
return fwrite(sector, 1, BYTES_PER_SECTOR, file) != BYTES_PER_SECTOR; return fwrite(sector, 1, BYTES_PER_SECTOR, file) == BYTES_PER_SECTOR;
} }
static unsigned int write_empty(FILE* file, u64 count) static bool write_empty(FILE* file, u64 count)
{ {
static u8 empty[64 * 1024]; static u8 empty[64 * 1024];
@ -194,11 +194,11 @@ static unsigned int write_empty(FILE* file, u64 count)
len = count; len = count;
if (fwrite(empty, 1, (size_t)len, file) != (size_t)len) if (fwrite(empty, 1, (size_t)len, file) != (size_t)len)
return 1; return false;
count -= len; count -= len;
} }
return 0; return true;
} }
bool SDCardCreate(u64 disk_size /*in MB*/, const std::string& filename) bool SDCardCreate(u64 disk_size /*in MB*/, const std::string& filename)
@ -245,45 +245,45 @@ bool SDCardCreate(u64 disk_size /*in MB*/, const std::string& filename)
* zero sectors * zero sectors
*/ */
if (write_sector(f, s_boot_sector)) if (!write_sector(f, s_boot_sector))
goto FailWrite; goto FailWrite;
if (write_sector(f, s_fsinfo_sector)) if (!write_sector(f, s_fsinfo_sector))
goto FailWrite; goto FailWrite;
if (BACKUP_BOOT_SECTOR > 0) if (BACKUP_BOOT_SECTOR > 0)
{ {
if (write_empty(f, BACKUP_BOOT_SECTOR - 2)) if (!write_empty(f, BACKUP_BOOT_SECTOR - 2))
goto FailWrite; goto FailWrite;
if (write_sector(f, s_boot_sector)) if (!write_sector(f, s_boot_sector))
goto FailWrite; goto FailWrite;
if (write_sector(f, s_fsinfo_sector)) if (!write_sector(f, s_fsinfo_sector))
goto FailWrite; goto FailWrite;
if (write_empty(f, RESERVED_SECTORS - 2 - BACKUP_BOOT_SECTOR)) if (!write_empty(f, RESERVED_SECTORS - 2 - BACKUP_BOOT_SECTOR))
goto FailWrite; goto FailWrite;
} }
else else
{ {
if (write_empty(f, RESERVED_SECTORS - 2)) if (!write_empty(f, RESERVED_SECTORS - 2))
goto FailWrite; goto FailWrite;
} }
if (write_sector(f, s_fat_head)) if (!write_sector(f, s_fat_head))
goto FailWrite; goto FailWrite;
if (write_empty(f, sectors_per_fat - 1)) if (!write_empty(f, sectors_per_fat - 1))
goto FailWrite; goto FailWrite;
if (write_sector(f, s_fat_head)) if (!write_sector(f, s_fat_head))
goto FailWrite; goto FailWrite;
if (write_empty(f, sectors_per_fat - 1)) if (!write_empty(f, sectors_per_fat - 1))
goto FailWrite; goto FailWrite;
if (write_empty(f, sectors_per_disk - RESERVED_SECTORS - 2 * sectors_per_fat)) if (!write_empty(f, sectors_per_disk - RESERVED_SECTORS - 2 * sectors_per_fat))
goto FailWrite; goto FailWrite;
return true; return true;