Merge pull request #1209 from mattx433/feature/mo_posix
Make mo_format use POSIX functions instead of Win32 ones
This commit is contained in:
@@ -22,6 +22,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include <wchar.h>
|
#include <wchar.h>
|
||||||
#define HAVE_STDARG_H
|
#define HAVE_STDARG_H
|
||||||
#include <86box/86box.h>
|
#include <86box/86box.h>
|
||||||
@@ -42,7 +43,7 @@
|
|||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <io.h>
|
#include <io.h>
|
||||||
#else
|
#else
|
||||||
#include <unistd.h>
|
#include <errno.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
mo_drive_t mo_drives[MO_NUM];
|
mo_drive_t mo_drives[MO_NUM];
|
||||||
@@ -1041,46 +1042,41 @@ mo_format(mo_t *dev)
|
|||||||
{
|
{
|
||||||
unsigned long size;
|
unsigned long size;
|
||||||
int ret;
|
int ret;
|
||||||
int fd;
|
int fd = fileno(dev->drv->f);
|
||||||
|
int64_t liSize = 0;
|
||||||
|
|
||||||
mo_log("MO %i: Formatting media...\n", dev->id);
|
mo_log("MO %i: Formatting media...\n", dev->id);
|
||||||
|
|
||||||
|
if (fd == -1) {
|
||||||
|
mo_log("MO %i: Failed to get file descriptor.\n", dev->id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
fseek(dev->drv->f, 0, SEEK_END);
|
fseek(dev->drv->f, 0, SEEK_END);
|
||||||
size = (uint32_t) ftello64(dev->drv->f);
|
size = (uint32_t) ftello64(dev->drv->f);
|
||||||
|
|
||||||
HANDLE fh;
|
errno = 0;
|
||||||
LARGE_INTEGER liSize;
|
rewind(dev->drv->f);
|
||||||
|
|
||||||
fd = _fileno(dev->drv->f);
|
if (errno) {
|
||||||
fh = (HANDLE)_get_osfhandle(fd);
|
|
||||||
|
|
||||||
liSize.QuadPart = 0;
|
|
||||||
|
|
||||||
ret = (int)SetFilePointerEx(fh, liSize, NULL, FILE_BEGIN);
|
|
||||||
|
|
||||||
if (!ret) {
|
|
||||||
mo_log("MO %i: Failed seek to start of image file\n", dev->id);
|
mo_log("MO %i: Failed seek to start of image file\n", dev->id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = (int)SetEndOfFile(fh);
|
ret = ftruncate(fd, 0);
|
||||||
|
if (ret == -1) {
|
||||||
if (!ret) {
|
|
||||||
mo_log("MO %i: Failed to truncate image file to 0\n", dev->id);
|
mo_log("MO %i: Failed to truncate image file to 0\n", dev->id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
liSize.QuadPart = size;
|
liSize = size;
|
||||||
ret = (int)SetFilePointerEx(fh, liSize, NULL, FILE_BEGIN);
|
ret = fseek(dev->drv->f, 0, SEEK_END);
|
||||||
|
if (ret == -1) {
|
||||||
if (!ret) {
|
|
||||||
mo_log("MO %i: Failed seek to end of image file\n", dev->id);
|
mo_log("MO %i: Failed seek to end of image file\n", dev->id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
ret = ftruncate(fd, liSize);
|
||||||
ret = (int)SetEndOfFile(fh);
|
if (ret == -1) {
|
||||||
|
|
||||||
if (!ret) {
|
|
||||||
mo_log("MO %i: Failed to truncate image file to %llu\n", dev->id, size);
|
mo_log("MO %i: Failed to truncate image file to %llu\n", dev->id, size);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user