VirtualBox

source: vbox/trunk/src/VBox/Runtime/r3/posix/RTSystemQueryOSInfo-posix.cpp@ 76452

Last change on this file since 76452 was 76452, checked in by vboxsync, 6 years ago

IPRT: Ran scm --fix-err-h. bugref:9344

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.1 KB
Line 
1/* $Id: RTSystemQueryOSInfo-posix.cpp 76452 2018-12-25 01:41:25Z vboxsync $ */
2/** @file
3 * IPRT - RTSystemQueryOSInfo, POSIX implementation.
4 */
5
6/*
7 * Copyright (C) 2008-2017 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27
28/*********************************************************************************************************************************
29* Header Files *
30*********************************************************************************************************************************/
31#include <iprt/system.h>
32#include <iprt/assert.h>
33#include <iprt/string.h>
34#include <iprt/errcore.h>
35
36#include <errno.h>
37#include <sys/utsname.h>
38
39
40RTDECL(int) RTSystemQueryOSInfo(RTSYSOSINFO enmInfo, char *pszInfo, size_t cchInfo)
41{
42 /*
43 * Quick validation.
44 */
45 AssertReturn(enmInfo > RTSYSOSINFO_INVALID && enmInfo < RTSYSOSINFO_END, VERR_INVALID_PARAMETER);
46 AssertPtrReturn(pszInfo, VERR_INVALID_POINTER);
47 if (!cchInfo)
48 return VERR_BUFFER_OVERFLOW;
49
50 /*
51 * Handle the request.
52 */
53 switch (enmInfo)
54 {
55 case RTSYSOSINFO_PRODUCT:
56 case RTSYSOSINFO_RELEASE:
57 case RTSYSOSINFO_VERSION:
58 {
59 struct utsname UtsInfo;
60 if (uname(&UtsInfo) < 0)
61 return RTErrConvertFromErrno(errno);
62 const char *pszSrc;
63 switch (enmInfo)
64 {
65 case RTSYSOSINFO_PRODUCT: pszSrc = UtsInfo.sysname; break;
66 case RTSYSOSINFO_RELEASE: pszSrc = UtsInfo.release; break;
67 case RTSYSOSINFO_VERSION: pszSrc = UtsInfo.version; break;
68 default: AssertFatalFailed(); /* screw gcc */
69 }
70 size_t cch = strlen(pszSrc);
71 if (cch < cchInfo)
72 {
73 memcpy(pszInfo, pszSrc, cch + 1);
74 return VINF_SUCCESS;
75 }
76 memcpy(pszInfo, pszSrc, cchInfo - 1);
77 pszInfo[cchInfo - 1] = '\0';
78 return VERR_BUFFER_OVERFLOW;
79 }
80
81
82 case RTSYSOSINFO_SERVICE_PACK:
83 default:
84 *pszInfo = '\0';
85 return VERR_NOT_SUPPORTED;
86 }
87
88 return VINF_SUCCESS;
89}
90
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette