nss: upgrade to release 3.73
[LibreOffice.git] / vcl / unx / generic / app / geninst.cxx
blob0093f64376c6aa4e0f01e481fe2615102f4b2674
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/config.h>
22 #if defined(LINUX)
23 # include <stdio.h>
24 #endif
25 #if defined(__FreeBSD__)
26 # include <sys/utsname.h>
27 #endif
29 #include <config_features.h>
30 #if HAVE_FEATURE_OPENGL
31 #include <vcl/opengl/OpenGLContext.hxx>
32 #endif
33 #include <unx/geninst.h>
35 // SalYieldMutex
37 SalYieldMutex::SalYieldMutex()
39 #if HAVE_FEATURE_OPENGL
40 SetBeforeReleaseHandler( &OpenGLContext::prepareForYield );
41 #endif
44 SalYieldMutex::~SalYieldMutex()
48 SalGenericInstance::~SalGenericInstance()
52 OUString SalGenericInstance::getOSVersion()
54 OUString aKernelVer = "unknown";
56 #if defined(LINUX)
57 FILE* pVersion = fopen( "/proc/version", "r" );
58 if ( pVersion )
60 char aVerBuffer[512];
61 if ( fgets ( aVerBuffer, 511, pVersion ) )
63 aKernelVer = OUString::createFromAscii( aVerBuffer );
64 // "Linux version 3.16.7-29-desktop ..."
65 OUString aVers = aKernelVer.getToken( 2, ' ' );
66 // "3.16.7-29-desktop ..."
67 sal_Int32 nTooDetailed = aVers.indexOf( '.', 2);
68 if (nTooDetailed < 1 || nTooDetailed > 8)
69 aKernelVer = "Linux (misparsed version)";
70 else // "3.16.7-29-desktop ..."
71 aKernelVer = OUString::Concat("Linux ") + aVers.subView(0, nTooDetailed);
73 fclose( pVersion );
75 return aKernelVer;
76 #elif defined(__FreeBSD__)
77 struct utsname stName;
78 if ( uname( &stName ) != 0 )
79 return aKernelVer;
81 sal_Int32 nDots = 0;
82 sal_Int32 nIndex = 0;
83 aKernelVer = OUString::createFromAscii( stName.release );
84 while ( nIndex++ < aKernelVer.getLength() )
86 const char c = stName.release[ nIndex ];
87 if ( c == ' ' || c == '-' || ( c == '.' && nDots++ > 0 ) )
88 break;
90 return OUString::createFromAscii( stName.sysname ) + " " +
91 aKernelVer.copy( 0, nIndex );
92 #else
93 return aKernelVer;
94 #endif
97 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */