Skip to content

Commit dc32513

Browse files
committed
webOS: add webOS TV version to log and system information screen
1 parent 513dd4e commit dc32513

File tree

2 files changed

+126
-1
lines changed

2 files changed

+126
-1
lines changed

frontend/drivers/platform_unix.c

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,6 +1299,110 @@ static enum frontend_architecture frontend_unix_get_arch(void)
12991299
return FRONTEND_ARCH_NONE;
13001300
}
13011301

1302+
#ifdef WEBOS
1303+
const char *retroarch_get_webos_version(char *s, size_t len,
1304+
int *major, int *minor)
1305+
{
1306+
static char pretty[128];
1307+
1308+
FILE *f = fopen("/usr/lib/os-release", "r");
1309+
if (!f)
1310+
{
1311+
/* fallback to starfish-release */
1312+
f = fopen("/etc/starfish-release", "r");
1313+
if (!f)
1314+
return strlcpy(s, "webOS (unknown)", len), "webOS (unknown)";
1315+
1316+
/* Example content:
1317+
Rockhopper release 3.9.0-62709 (dreadlocks2-dudhwa) */
1318+
char line[256];
1319+
if (fgets(line, sizeof(line), f))
1320+
{
1321+
char *nl = strchr(line, '\n');
1322+
if (nl) *nl = '\0';
1323+
snprintf(pretty, sizeof(pretty), "webOS - %s", line);
1324+
1325+
/* Try parse after the word "release", else first digit run in the line */
1326+
char *ver = strstr(line, "release");
1327+
if (ver)
1328+
{
1329+
ver += strlen("release");
1330+
while (*ver == ' ') ver++;
1331+
}
1332+
else
1333+
{
1334+
/* find first digit in the line */
1335+
ver = line;
1336+
while (*ver && ((*ver < '0') || (*ver > '9'))) ver++;
1337+
if (!*ver) ver = NULL;
1338+
}
1339+
1340+
if (ver)
1341+
{
1342+
char *endptr = NULL;
1343+
long maj = strtol(ver, &endptr, 10);
1344+
if (endptr != ver)
1345+
{
1346+
if (major) *major = (int)maj;
1347+
if (endptr && *endptr == '.' && minor)
1348+
{
1349+
long min = strtol(endptr + 1, NULL, 10);
1350+
/* only set minor if a number was present */
1351+
const char *p = endptr + 1;
1352+
if (p && (*p >= '0' && *p <= '9'))
1353+
*minor = (int)min;
1354+
}
1355+
}
1356+
}
1357+
}
1358+
fclose(f);
1359+
1360+
if (pretty[0] == '\0')
1361+
strlcpy(pretty, "webOS (unknown)", sizeof(pretty));
1362+
1363+
return strlcpy(s, pretty, len), pretty;
1364+
}
1365+
1366+
char line[256];
1367+
while (fgets(line, sizeof(line), f))
1368+
{
1369+
if (strncmp(line, "PRETTY_NAME=", 12) == 0)
1370+
{
1371+
char *val = line + 12;
1372+
char *nl = strchr(val, '\n');
1373+
if (nl) *nl = '\0';
1374+
if ((val[0] == '"' || val[0] == '\'')) {
1375+
size_t l = strlen(val);
1376+
if (l > 1 && val[l-1] == val[0]) {
1377+
val[l-1] = '\0';
1378+
val++;
1379+
}
1380+
}
1381+
strlcpy(pretty, val, sizeof(pretty));
1382+
}
1383+
else if (strncmp(line, "VERSION_ID=", 11) == 0)
1384+
{
1385+
char *val = line + 11;
1386+
char *nl = strchr(val, '\n');
1387+
if (nl) *nl = '\0';
1388+
char *endptr = NULL;
1389+
long maj = strtol(val, &endptr, 10);
1390+
if (major) *major = (int)maj;
1391+
if (endptr && *endptr == '.' && minor)
1392+
*minor = (int)strtol(endptr+1, NULL, 10);
1393+
else if (minor)
1394+
*minor = 0;
1395+
}
1396+
}
1397+
fclose(f);
1398+
1399+
if (pretty[0] == '\0')
1400+
strlcpy(pretty, "webOS (unknown)", sizeof(pretty));
1401+
1402+
return strlcpy(s, pretty, len), pretty;
1403+
}
1404+
#endif
1405+
13021406
static size_t frontend_unix_get_os(char *s,
13031407
size_t len, int *major, int *minor)
13041408
{
@@ -1326,6 +1430,8 @@ static size_t frontend_unix_get_os(char *s,
13261430
_len = strlcpy(s, "BSD", len);
13271431
#elif defined(__HAIKU__)
13281432
_len = strlcpy(s, "Haiku", len);
1433+
#elif defined(WEBOS)
1434+
_len = strlcpy(s, retroarch_get_webos_version(s, len, major, minor), len);
13291435
#else
13301436
_len = strlcpy(s, "Linux", len);
13311437
#endif

retroarch.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7876,12 +7876,31 @@ bool retroarch_main_init(int argc, char *argv[])
78767876
if (verbosity_enabled)
78777877
{
78787878
{
7879-
char str_output[256];
7879+
char str_output[384];
78807880
const char *cpu_model = frontend_driver_get_cpu_model_name();
78817881
size_t _len = strlcpy(str_output,
78827882
"=== Build =======================================\n",
78837883
sizeof(str_output));
78847884

7885+
#ifdef WEBOS
7886+
{
7887+
char osbuf[128];
7888+
int major = 0, minor = 0;
7889+
frontend_state_t *frontend_st = frontend_state_get_ptr();
7890+
if (frontend_st)
7891+
{
7892+
frontend_ctx_driver_t *frontend = frontend_st->current_frontend_ctx;
7893+
if (frontend && frontend->get_os)
7894+
{
7895+
frontend->get_os(osbuf, sizeof(osbuf), &major, &minor);
7896+
_len += snprintf(str_output + _len, sizeof(str_output) - _len,
7897+
FILE_PATH_LOG_INFO " Running on: %s\n",
7898+
osbuf);
7899+
}
7900+
}
7901+
}
7902+
#endif
7903+
78857904
if (!string_is_empty(cpu_model))
78867905
{
78877906
/* TODO/FIXME - localize */

0 commit comments

Comments
 (0)