Merge pull request #5614 from josch1710/master

More OS/2 porting
This commit is contained in:
Jonathan Campbell 2025-04-06 23:52:34 -07:00 committed by GitHub
commit d5e150f1db
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 54 additions and 30 deletions

View File

@ -36,6 +36,9 @@
#include <fcntl.h>
#include <sys/utime.h>
#include <sys/locking.h>
#ifdef OS2
#include <sys/time.h>
#endif
#endif
#include <sys/stat.h>
@ -2962,26 +2965,26 @@ bool LocalFile::Seek(uint32_t * pos,uint32_t type) {
bool LocalFile::Close() {
if (!newtime && fhandle && last_action == WRITE) UpdateLocalDateTime();
if (newtime && fhandle) {
if (newtime && fhandle) {
// force STDIO to flush buffers on this file handle, or else fclose() will write buffered data
// and cause mtime to reset back to current time.
fflush(fhandle);
// backport from DOS_PackDate() and DOS_PackTime()
struct tm tim = { 0 };
tim.tm_sec = (time&0x1f)*2;
tim.tm_min = (time>>5)&0x3f;
tim.tm_hour = (time>>11)&0x1f;
tim.tm_mday = date&0x1f;
tim.tm_mon = ((date>>5)&0x0f)-1;
tim.tm_year = (date>>9)+1980-1900;
// backport from DOS_PackDate() and DOS_PackTime()
struct tm tim = { 0 };
tim.tm_sec = (time&0x1f)*2;
tim.tm_min = (time>>5)&0x3f;
tim.tm_hour = (time>>11)&0x1f;
tim.tm_mday = date&0x1f;
tim.tm_mon = ((date>>5)&0x0f)-1;
tim.tm_year = (date>>9)+1980-1900;
// sanitize the date in case of invalid timestamps (such as 0x0000 date/time fields)
if (tim.tm_mon < 0) tim.tm_mon = 0;
if (tim.tm_mday == 0) tim.tm_mday = 1;
// have the C run-time library code compute whether standard time or daylight saving time is in effect.
tim.tm_isdst = -1;
// serialize time
mktime(&tim);
// have the C run-time library code compute whether standard time or daylight saving time is in effect.
tim.tm_isdst = -1;
// serialize time
mktime(&tim);
// change file time by file handle (while we still have it open)
// so that we do not have to duplicate guest to host filename conversion here.
@ -2996,7 +2999,13 @@ bool LocalFile::Close() {
LOG_MSG("Set time failed (%s)", strerror(errno));
}
#elif defined(OS2)
LOG_MSG("File set time TBD");
struct timeval ftsp[2];
ftsp[0].tv_sec = ftsp[1].tv_sec = mktime(&tim);
ftsp[0].tv_usec = ftsp[1].tv_usec = 0;
if (futimes(fileno(fhandle), ftsp)) {
extern int errno;
LOG_MSG("Set time failed (%s)", strerror(errno));
}
#elif !defined(RISCOS) // Linux (TODO: What about Mac OS X/Darwin?)
// NTS: Do not attempt futime, Linux doesn't have it.
// Do not attempt futimes, Linux man pages LIE about having it. It's even there in the freaking header, but not recognized!
@ -3010,16 +3019,16 @@ bool LocalFile::Close() {
LOG_MSG("Set time failed (%s)", strerror(errno));
}
#endif
}
}
// only close if one reference left
if (refCtr==1) {
if(fhandle) fclose(fhandle);
fhandle = nullptr;
open = false;
}
// only close if one reference left
if (refCtr==1) {
if(fhandle) fclose(fhandle);
fhandle = nullptr;
open = false;
}
return true;
return true;
}
uint16_t LocalFile::GetInformation(void) {

View File

@ -35,6 +35,7 @@
#ifdef OS2
# define INCL_DOS
# define INCL_WIN
# define INCL_DOSERRORS
#endif
#if defined(WIN32)
@ -135,7 +136,7 @@ bool kana_input = false; // true if a half-width kana was typed
#include "../dos/drives.h"
#include "../ints/int10.h"
#if !defined(HX_DOS)
#if !defined(__MINGW32__) || defined(__MINGW64_VERSION_MAJOR)
#if !defined(OS2) && !defined(__MINGW32__) || defined(__MINGW64_VERSION_MAJOR)
#include "whereami.c"
#endif
#include "../libs/tinyfiledialogs/tinyfiledialogs.h"
@ -218,6 +219,11 @@ typedef enum PROCESS_DPI_AWARENESS {
# endif
#endif // WIN32
#ifdef OS2
# include <os2.h>
#endif
#include <sstream>
#include "mapper.h"
@ -239,7 +245,7 @@ extern "C" void sdl1_hax_macosx_highdpi_set_enable(const bool enable);
#endif
# include "SDL_version.h"
#if !defined(C_SDL2) && !defined(RISCOS)
#if !defined(C_SDL2) && !defined(RISCOS) && !defined(OS2)
# ifndef SDL_DOSBOX_X_SPECIAL
# warning It is STRONGLY RECOMMENDED to compile the DOSBox-X code using the SDL 1.x library provided in this source repository.
# error You can ignore this by commenting out this error, but you will encounter problems if you use the unmodified SDL 1.x library.
@ -442,6 +448,19 @@ std::string GetDOSBoxXPath(bool withexe=false) {
char exepath[MAX_PATH];
GetModuleFileName(NULL, exepath, sizeof(exepath));
full=std::string(exepath);
#elif defined(OS2) /* No WAI */
char exepath[CCHMAXPATH];
PPIB pib;
APIRET rc;
full = std::string("");
rc = DosGetInfoBlocks(NULL, &pib);
if (rc == NO_ERROR) {
rc = DosQueryModuleName(pib->pib_hmte, CCHMAXPATH, (PCHAR)&exepath);
if (rc == NO_ERROR) {
full = std::string(exepath);
}
}
#else
int length = wai_getExecutablePath(NULL, 0, NULL);
char *exepath = (char*)malloc(length + 1);
@ -897,10 +916,6 @@ const char *modifier;
# define PRIO_TOTAL (PRIO_MAX-PRIO_MIN)
#endif
#ifdef OS2
# include <os2.h>
#endif
#if defined(WIN32)
HWND GetHWND(void) {
SDL_SysWMinfo wmi;

View File

@ -27,8 +27,8 @@
// C++ SDLnet wrapper
#if !defined(__MINGW32__) || defined(__MINGW64_VERSION_MAJOR)
#define ENET_IMPLEMENTATION
#include "enet.h"
#define ENET_IMPLEMENTATION
#include "enet.h"
#endif
#include "ipx.h"
#include "logging.h"