Skip to content

Commit c0a9b62

Browse files
author
Mikachu2333
committed
fix(lib): 修复操作系统检测逻辑
1. 回退linux检测 2. 补充缺少的return
1 parent b5cf57b commit c0a9b62

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

lib/xy.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,11 +1284,23 @@ xy_detect_os ()
12841284
}
12851285
}
12861286

1287-
// REF: https://android.googlesource.com/platform/system/core/+/refs/heads/main/rootdir/init.environ.rc.in
1287+
FILE *fp = fopen ("/proc/version", "r");
1288+
if (fp)
1289+
{
1290+
char buf[256] = {0};
1291+
fread (buf, 1, sizeof(buf) - 1, fp);
1292+
fclose (fp);
1293+
if (strstr (buf, "Linux"))
1294+
{
1295+
xy.on_linux = true;
1296+
return;
1297+
}
1298+
}
1299+
1300+
// @consult https://android.googlesource.com/platform/system/core/+/refs/heads/main/rootdir/init.environ.rc.in
12881301
char *android_env = getenv ("ANDROID_ROOT");
12891302
if (xy_str_find (android_env, "/system").found)
12901303
{
1291-
xy.on_linux = true;
12921304
xy.on_android = true;
12931305
return;
12941306
}
@@ -1303,6 +1315,7 @@ xy_detect_os ()
13031315
{
13041316
xy.on_macos = true;
13051317
closedir (d);
1318+
return;
13061319
}
13071320
}
13081321

@@ -1324,6 +1337,7 @@ xy_detect_os ()
13241337
pclose (fp);
13251338
if (strstr (buf, "BSD") != NULL)
13261339
xy.on_bsd = true;
1340+
return;
13271341
}
13281342

13291343
if (!(xy.on_windows || xy.on_linux || xy.on_android || xy.on_macos || xy.on_bsd))

0 commit comments

Comments
 (0)