Skip to content

Commit 6af3e51

Browse files
author
Mikachu2333
authored
修复Android系统检测 (#313)
1 parent 730d18a commit 6af3e51

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

lib/xy.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,18 +1290,21 @@ xy_detect_os ()
12901290
char buf[256] = {0};
12911291
fread (buf, 1, sizeof(buf) - 1, fp);
12921292
fclose (fp);
1293-
if (strstr (buf, "Android"))
1294-
{
1295-
xy.on_android = true;
1296-
return;
1297-
}
1298-
else if (strstr (buf, "Linux"))
1293+
if (strstr (buf, "Linux"))
12991294
{
13001295
xy.on_linux = true;
13011296
return;
13021297
}
13031298
}
13041299

1300+
// @consult https://android.googlesource.com/platform/system/core/+/refs/heads/main/rootdir/init.environ.rc.in
1301+
char *android_env = getenv ("ANDROID_ROOT");
1302+
if (xy_str_find (android_env, "/system").found)
1303+
{
1304+
xy.on_android = true;
1305+
return;
1306+
}
1307+
13051308
/* 判断 macOS */
13061309
DIR *d = opendir ("/System/Applications");
13071310
if (d)
@@ -1312,6 +1315,7 @@ xy_detect_os ()
13121315
{
13131316
xy.on_macos = true;
13141317
closedir (d);
1318+
return;
13151319
}
13161320
}
13171321

@@ -1333,6 +1337,7 @@ xy_detect_os ()
13331337
pclose (fp);
13341338
if (strstr (buf, "BSD") != NULL)
13351339
xy.on_bsd = true;
1340+
return;
13361341
}
13371342

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

0 commit comments

Comments
 (0)