From 6d337b7b7b0886700cf0307edfab18b01ca60156 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E8=AB=8F=E8=A8=AA=E5=AD=90?= Date: Tue, 10 Dec 2024 02:46:33 +0900 Subject: [PATCH] =?utf8?q?segfault=E3=81=A8musl=E3=81=A7=E3=82=B3=E3=83=B3?= =?utf8?q?=E3=83=91=E3=82=A4=E3=83=AB=E3=82=A8=E3=83=A9=E3=83=BC=E3=81=AE?= =?utf8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- main.c | 13 +++++++++++++ src/common.c | 16 +++++++++++++++- src/common.h | 1 + 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/main.c b/main.c index 374c7ab..451fa0a 100644 --- a/main.c +++ b/main.c @@ -79,6 +79,19 @@ int main(int argc, char *argv[]) { } Config *cf = getconfig(); + if (cf == NULL) { +#if defined (_WIN32) + const char *cnfpath = "type nul > \\AppData\\Local\\076\\sp\\sp.conf"; +#elif defined (__HAIKU__) + const char *cnfpath = "touch /boot/home/config/settings/sp/sp.conf"; +#else + const char *cnfpath = "touch ~/config/sp.conf"; +#endif + printf("コンフィグファイルを見つけられません。" + "「%s」を実効して下さい。\n", cnfpath); + return -1; + + } lang = getlang(cf); if (strcmp(argv[1], "-g") == 0) { diff --git a/src/common.c b/src/common.c index 7fe67c3..89dbb18 100644 --- a/src/common.c +++ b/src/common.c @@ -2,6 +2,9 @@ #include #include +#if defined(__MUSL__) +#include +#endif #include #include #include @@ -13,6 +16,17 @@ int copyTimeFromCnf; int otpTimeFromCnf; Config *cnf; +#if defined(__MUSL__) +char *strcasestr(const char *haystack, const char *needle) { + size_t len = strlen(needle); + for (const char *p = haystack; *p; p++) { + if (strncasecmp(p, needle, len) == 0) return (char *)p; + } + + return NULL; +} +#endif + Config *getconfig() { const char *configpath = getconfigpath(); if (!configpath) { @@ -29,11 +43,11 @@ Config *getconfig() { cnf->passtimeout = 45; cnf->otptimeout = 30; strncpy(cnf->language, "ja", sizeof(cnf->language) - 1); + cnf->language[sizeof(cnf->language) - 1] = '\0'; cnf->syncname[sizeof(cnf->syncname) - 1] = '\0'; cnf->syncpass[sizeof(cnf->syncpass) - 1] = '\0'; cnf->syncinstance[sizeof(cnf->syncinstance) - 1] = '\0'; - cnf->language[sizeof(cnf->language) - 1] = '\0'; FILE *fp = fopen(configpath, "r"); if (!fp) { diff --git a/src/common.h b/src/common.h index 557f1c7..46141f2 100644 --- a/src/common.h +++ b/src/common.h @@ -32,6 +32,7 @@ typedef struct { char language[3]; } Config; +char *strcasestr(const char *haystack, const char *needle); Config *getconfig(); const char *getconfigpath(); char *getbasedir(int trailing); -- 2.43.0