Coverage Report

Created: 2026-10-14 09:33

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/vcl/unx/generic/app/geninst.cxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
5
 * This Source Code Form is subject to the terms of the Mozilla Public
6
 * License, v. 2.0. If a copy of the MPL was not distributed with this
7
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
 *
9
 * This file incorporates work covered by the following license notice:
10
 *
11
 *   Licensed to the Apache Software Foundation (ASF) under one or more
12
 *   contributor license agreements. See the NOTICE file distributed
13
 *   with this work for additional information regarding copyright
14
 *   ownership. The ASF licenses this file to you under the Apache
15
 *   License, Version 2.0 (the "License"); you may not use this file
16
 *   except in compliance with the License. You may obtain a copy of
17
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18
 */
19
20
#include <sal/config.h>
21
22
#if defined(LINUX)
23
#  include <stdio.h>
24
#endif
25
#if defined(__FreeBSD__)
26
#  include <sys/utsname.h>
27
#endif
28
#if defined(__EMSCRIPTEN__)
29
#include <emscripten/version.h>
30
#endif
31
32
#include <config_features.h>
33
#if HAVE_FEATURE_OPENGL
34
#include <vcl/opengl/OpenGLContext.hxx>
35
#endif
36
#include <unx/geninst.h>
37
#include <o3tl/string_view.hxx>
38
39
SalGenericInstance::~SalGenericInstance()
40
0
{
41
0
}
42
43
OUString SalGenericInstance::getOSVersion()
44
0
{
45
0
    OUString aKernelVer = u"unknown"_ustr;
46
0
#if defined(LINUX)
47
0
    FILE* pVersion = fopen( "/proc/version", "r" );
48
0
    if ( pVersion )
49
0
    {
50
0
        char aVerBuffer[512];
51
0
        if ( fgets ( aVerBuffer, 511, pVersion ) )
52
0
        {
53
0
            aKernelVer = OUString::createFromAscii( aVerBuffer );
54
            // "Linux version 3.16.7-29-desktop ..."
55
0
            std::u16string_view aVers = o3tl::getToken(aKernelVer, 2, ' ' );
56
            // "3.16.7-29-desktop ..."
57
0
            size_t nTooDetailed = aVers.find( '.', 2);
58
0
            if (nTooDetailed < 1 || nTooDetailed > 8)
59
0
                aKernelVer = "Linux (misparsed version)";
60
0
            else // "3.16.7-29-desktop ..."
61
0
                aKernelVer = OUString::Concat("Linux ") + aVers.substr(0, nTooDetailed);
62
0
        }
63
0
        fclose( pVersion );
64
0
    }
65
#elif defined(__FreeBSD__)
66
    struct utsname stName;
67
    if ( uname( &stName ) != 0 )
68
        return aKernelVer;
69
70
    sal_Int32 nDots = 0;
71
    sal_Int32 nIndex = 0;
72
    aKernelVer = OUString::createFromAscii( stName.release );
73
    while ( nIndex++ < aKernelVer.getLength() )
74
    {
75
        const char c = stName.release[ nIndex ];
76
        if ( c == ' ' || c == '-' || ( c == '.' && nDots++ > 0 ) )
77
            break;
78
    }
79
    aKernelVer = OUString::createFromAscii(stName.sysname) + " " + aKernelVer.copy(0, nIndex);
80
#elif defined(__EMSCRIPTEN__)
81
#if defined __EMSCRIPTEN_MAJOR__
82
    aKernelVer = u"Emscripten "_ustr + OUString::number(__EMSCRIPTEN_MAJOR__) + u"."_ustr
83
                 + OUString::number(__EMSCRIPTEN_MINOR__) + u"."_ustr
84
                 + OUString::number(__EMSCRIPTEN_TINY__);
85
#else
86
    aKernelVer = u"Emscripten "_ustr + OUString::number(__EMSCRIPTEN_major__) + u"."_ustr
87
                 + OUString::number(__EMSCRIPTEN_minor__) + u"."_ustr
88
                 + OUString::number(__EMSCRIPTEN_tiny__);
89
#endif
90
#endif
91
0
    return aKernelVer;
92
0
}
93
94
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */