mirror of
https://github.com/kichikuou/xsystem35-sdl2.git
synced 2026-10-13 01:28:14 +03:00
Windows MSYS2 build support
- Add feature detection and fallback implementation for some functions - Use binary mode for fopen() - CMake: Add workaround for MSYS link error
This commit is contained in:
+1
-1
@@ -72,7 +72,7 @@ static void bgi_read() {
|
||||
if (nact->files.bgi == NULL)
|
||||
return;
|
||||
|
||||
FILE *fp = fopen(nact->files.bgi, "r");
|
||||
FILE *fp = fopen(nact->files.bgi, "rb");
|
||||
if (!fp) {
|
||||
WARNING("Could not open %s\n", nact->files.bgi);
|
||||
return;
|
||||
|
||||
+10
-4
@@ -25,7 +25,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/utsname.h>
|
||||
#include "portab.h"
|
||||
#include "xsystem35.h"
|
||||
#include "savedata.h"
|
||||
@@ -38,6 +37,9 @@
|
||||
#include "graphicsdevice.h"
|
||||
#include "ald_manager.h"
|
||||
#include "LittleEndian.h"
|
||||
#if HAVE_UNAME
|
||||
#include <sys/utsname.h>
|
||||
#endif
|
||||
|
||||
/* defined by cmdm.c */
|
||||
extern boolean have_eng_mp_patch;
|
||||
@@ -868,17 +870,21 @@ void commands2F51() {
|
||||
|
||||
void commands2F52() {
|
||||
int eNum = getCaliValue();
|
||||
if (eNum <= 0) return;
|
||||
|
||||
#if HAVE_UNAME
|
||||
struct utsname un;
|
||||
char s[256];
|
||||
|
||||
if (eNum <= 0) return;
|
||||
if (uname(&un) < 0) return;
|
||||
NOTICE("sysname %s nodename %s release %s version %s machine %s\n",
|
||||
un.sysname, un.nodename, un.release, un.version, un.machine);
|
||||
sprintf(s,"%s %s %s",
|
||||
un.sysname, un.release, un.machine);
|
||||
#else
|
||||
const char *s = CMAKE_SYSTEM_NAME;
|
||||
#endif
|
||||
|
||||
v_strcpy(eNum -1, s);
|
||||
|
||||
DEBUG_COMMAND("sysGetOsName %d: %s\n", eNum, s);
|
||||
}
|
||||
|
||||
|
||||
+7
-7
@@ -449,16 +449,16 @@ void commandZZ13() {
|
||||
|
||||
void commandZZ14() {
|
||||
int no = getCaliValue();
|
||||
char *s = "xsys35_user";
|
||||
|
||||
#ifdef HAVE_GETLOGIN
|
||||
char *lname=getlogin();
|
||||
if (lname)
|
||||
s = lname;
|
||||
#endif
|
||||
|
||||
if (no <= 0) return;
|
||||
if (lname) {
|
||||
v_strcpy(no -1, lname);
|
||||
} else {
|
||||
char s[256];
|
||||
sprintf(s, "%d", getuid());
|
||||
v_strcpy(no -1, s);
|
||||
}
|
||||
v_strcpy(no -1, s);
|
||||
|
||||
DEBUG_COMMAND("ZZ14 %d:\n", no);
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
@@ -34,6 +33,9 @@
|
||||
#include "system.h"
|
||||
#include "LittleEndian.h"
|
||||
#include "dri.h"
|
||||
#ifdef HAVE_MMAP
|
||||
#include <sys/mman.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
* static maethods
|
||||
@@ -184,7 +186,7 @@ drifiles *dri_init(char **file, int cnt, boolean mmapping) {
|
||||
for (i = 0; i < cnt; i++) {
|
||||
if (*(file + i) == NULL) continue;
|
||||
/* open check */
|
||||
if (NULL == (fp = fopen(*(file + i), "r"))) {
|
||||
if (NULL == (fp = fopen(*(file + i), "rb"))) {
|
||||
SYSERROR("File %s is not found\n", *(file + i));
|
||||
}
|
||||
/* check is drifile or noe */
|
||||
@@ -204,6 +206,7 @@ drifiles *dri_init(char **file, int cnt, boolean mmapping) {
|
||||
d->fnames[i] = strdup(*(file + i));
|
||||
/* close */
|
||||
fclose(fp);
|
||||
#ifdef HAVE_MMAP
|
||||
/* mmap */
|
||||
if (mmapping) {
|
||||
int fd;
|
||||
@@ -219,6 +222,7 @@ drifiles *dri_init(char **file, int cnt, boolean mmapping) {
|
||||
}
|
||||
d->mmapped = TRUE;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return d;
|
||||
}
|
||||
@@ -257,7 +261,7 @@ dridata *dri_getdata(drifiles *d, int no) {
|
||||
int readsize = dataptr2 - dataptr;
|
||||
FILE *fp;
|
||||
data = malloc(sizeof(char) * readsize);
|
||||
fp = fopen(d->fnames[disk], "r");
|
||||
fp = fopen(d->fnames[disk], "rb");
|
||||
fseek(fp, dataptr, SEEK_SET);
|
||||
fread(data, 1, readsize, fp);
|
||||
fclose(fp);
|
||||
|
||||
+2
-2
@@ -98,9 +98,9 @@ FILE *fc_open(char *filename, char type) {
|
||||
FILE *fp;
|
||||
if (type == 'w') {
|
||||
fc_backup_oldfile(fullpath);
|
||||
fp = fopen(fullpath, "w");
|
||||
fp = fopen(fullpath, "wb");
|
||||
} else {
|
||||
fp = fopen(fullpath, "r");
|
||||
fp = fopen(fullpath, "rb");
|
||||
}
|
||||
free(fullpath);
|
||||
return fp;
|
||||
|
||||
+27
-1
@@ -28,7 +28,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
@@ -44,6 +43,9 @@
|
||||
#include "counter.h"
|
||||
#include "nact.h"
|
||||
#include "LittleEndian.h"
|
||||
#ifdef HAVE_MMAP
|
||||
#include <sys/mman.h>
|
||||
#endif
|
||||
|
||||
#define DEFAULT_AUDIO_BUFFER_SIZE 2048
|
||||
|
||||
@@ -359,15 +361,39 @@ static int load_wai() {
|
||||
goto endwai;
|
||||
}
|
||||
|
||||
#ifdef HAVE_MMAP
|
||||
if (MAP_FAILED == (adr = mmap(0, sbuf.st_size, PROT_READ, MAP_SHARED, fd, 0))) {
|
||||
WARNING("mmap: %s\n", strerror(errno));
|
||||
close(fd);
|
||||
goto endwai;
|
||||
}
|
||||
#else
|
||||
adr = malloc(sbuf.st_size);
|
||||
if (!adr) {
|
||||
WARNING("load_wai: out of memory\n");
|
||||
close(fd);
|
||||
goto endwai;
|
||||
}
|
||||
size_t bytes = 0;
|
||||
while (bytes < sbuf.st_size) {
|
||||
ssize_t ret = read(fd, adr, sbuf.st_size);
|
||||
if (ret <= 0) {
|
||||
WARNING("load_wai: failed to read\n");
|
||||
close(fd);
|
||||
free(adr);
|
||||
goto endwai;
|
||||
}
|
||||
bytes += ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (*adr != 'X' || *(adr+1) != 'I' || *(adr+2) != '2') {
|
||||
WARNING("not WAI file\n");
|
||||
#ifdef HAVE_MMAP
|
||||
munmap(adr, sbuf.st_size);
|
||||
#else
|
||||
free(adr);
|
||||
#endif
|
||||
close(fd);
|
||||
goto endwai;
|
||||
}
|
||||
|
||||
+2
-2
@@ -73,7 +73,7 @@ int s39ini_init(void) {
|
||||
|
||||
// Volume.sav があればそれを読み込む
|
||||
snprintf(fn, sizeof(fn) -1, "%s/Volume.sav", nact->files.savedir);
|
||||
if (NULL == (fp = fopen(fn, "r"))) {
|
||||
if (NULL == (fp = fopen(fn, "rb"))) {
|
||||
// とりあえず、初期ボリュームは 100
|
||||
for (i = 0; i < MAXVOLCH; i++) {
|
||||
vol[i] = vval[i].vol = 100;
|
||||
@@ -143,7 +143,7 @@ int s39ini_remove() {
|
||||
}
|
||||
|
||||
snprintf(fn, sizeof(fn) -1, "%s/Volume.sav", nact->files.savedir);
|
||||
if (NULL == (fp = fopen(fn, "w"))) {
|
||||
if (NULL == (fp = fopen(fn, "wb"))) {
|
||||
WARNING("Fail to save Volume.save\n");
|
||||
return NG;
|
||||
}
|
||||
|
||||
+22
-16
@@ -28,11 +28,14 @@
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#ifdef HAVE_SIGACTION
|
||||
#include <signal.h>
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_GTK
|
||||
# define GTK_RC_NAME ".gtk/gtkrc"
|
||||
# include <gtk/gtk.h>
|
||||
@@ -72,10 +75,7 @@ static void sys35_init();
|
||||
static void sys35_remove();
|
||||
static boolean sys35_initGameDataResorce();
|
||||
static void sys35_ParseOption(int *argc, char **argv);
|
||||
static void signal_handler(int sig_num);
|
||||
static void signal_handler_segv(int sig_num);
|
||||
static void check_profile();
|
||||
static void init_signalhandler();
|
||||
|
||||
/* for debugging */
|
||||
static FILE *fpdebuglog;
|
||||
@@ -543,17 +543,6 @@ void sys_reset() {
|
||||
sys_error("exec fail");
|
||||
}
|
||||
|
||||
static void signal_handler(int sig_num) {
|
||||
sys35_remove();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static void signal_handler_segv(int sig_num) {
|
||||
fprintf(stderr, "PID(%d), sigsegv caught @ %03d, %05x\n", (int)getpid(), sl_getPage(), sl_getIndex());
|
||||
sys35_remove();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static void sys35_ParseOption(int *argc, char **argv) {
|
||||
int i;
|
||||
FILE *fp;
|
||||
@@ -746,6 +735,18 @@ static void check_profile() {
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_SIGACTION
|
||||
static void signal_handler(int sig_num) {
|
||||
sys35_remove();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static void signal_handler_segv(int sig_num) {
|
||||
fprintf(stderr, "PID(%d), sigsegv caught @ %03d, %05x\n", (int)getpid(), sl_getPage(), sl_getIndex());
|
||||
sys35_remove();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void sys_set_signalhandler(int SIG, void (*handler)(int)) {
|
||||
struct sigaction act;
|
||||
sigset_t smask;
|
||||
@@ -760,17 +761,20 @@ void sys_set_signalhandler(int SIG, void (*handler)(int)) {
|
||||
sigaction(SIG, &act, NULL);
|
||||
}
|
||||
|
||||
void init_signalhandler() {
|
||||
static void init_signalhandler() {
|
||||
sys_set_signalhandler(SIGINT, signal_handler);
|
||||
sys_set_signalhandler(SIGTERM, signal_handler);
|
||||
sys_set_signalhandler(SIGPIPE, SIG_IGN);
|
||||
sys_set_signalhandler(SIGABRT, signal_handler);
|
||||
sys_set_signalhandler(SIGSEGV, signal_handler_segv);
|
||||
}
|
||||
#endif
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
char *homedir = getenv("HOME"), *rc_name, *rc_path;
|
||||
#ifdef HAVE_SIGACTION
|
||||
sys_set_signalhandler(SIGINT, SIG_IGN);
|
||||
#endif
|
||||
|
||||
saved_argc = argc;
|
||||
saved_argv = argv;
|
||||
@@ -788,7 +792,9 @@ int main(int argc, char **argv) {
|
||||
#endif
|
||||
sys35_initGameDataResorce();
|
||||
|
||||
#ifdef HAVE_SIGACTION
|
||||
init_signalhandler();
|
||||
#endif
|
||||
|
||||
mus_init(audio_buffer_size);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user