SDCardUtil: Make type of write_empty's "count" parameter size_t
This allows getting rid of casts. We can also leverage std::min to allow making relevant variables const. Also make the "empty" table const to allow it to be read-only.
This commit is contained in:
parent
c26de8107d
commit
1ffd0d2572
|
@ -32,6 +32,9 @@
|
||||||
// A simple and portable piece of code used to generate a blank FAT32 image file.
|
// A simple and portable piece of code used to generate a blank FAT32 image file.
|
||||||
// Modified for Dolphin.
|
// Modified for Dolphin.
|
||||||
|
|
||||||
|
#include "Common/SDCardUtil.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <cinttypes>
|
#include <cinttypes>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
@ -43,7 +46,6 @@
|
||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
#include "Common/File.h"
|
#include "Common/File.h"
|
||||||
#include "Common/Logging/Log.h"
|
#include "Common/Logging/Log.h"
|
||||||
#include "Common/SDCardUtil.h"
|
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
#include <unistd.h> // for unlink()
|
#include <unistd.h> // for unlink()
|
||||||
|
@ -182,18 +184,16 @@ 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 bool write_empty(FILE* file, u64 count)
|
static bool write_empty(FILE* file, std::size_t count)
|
||||||
{
|
{
|
||||||
static u8 empty[64 * 1024];
|
static constexpr u8 empty[64 * 1024] = {};
|
||||||
|
|
||||||
count *= BYTES_PER_SECTOR;
|
count *= BYTES_PER_SECTOR;
|
||||||
while (count > 0)
|
while (count > 0)
|
||||||
{
|
{
|
||||||
u64 len = sizeof(empty);
|
const std::size_t len = std::min(sizeof(empty), count);
|
||||||
if (len > count)
|
|
||||||
len = count;
|
|
||||||
|
|
||||||
if (fwrite(empty, 1, (size_t)len, file) != (size_t)len)
|
if (fwrite(empty, 1, len, file) != len)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
count -= len;
|
count -= len;
|
||||||
|
|
Loading…
Reference in New Issue