VirtualBox

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

Last change on this file since 44529 was 44529, checked in by vboxsync, 12 years ago

header (C) fixes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.9 KB
Line 
1/* $Id: RTSystemQueryOSInfo-posix.cpp 44529 2013-02-04 15:54:15Z vboxsync $ */
2/** @file
3 * IPRT - RTSystemQueryOSInfo, POSIX implementation.
4 */
5
6/*
7 * Copyright (C) 2008-2010 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* Header Files *
29*******************************************************************************/
30#include <iprt/system.h>
31#include <iprt/assert.h>
32#include <iprt/string.h>
33#include <iprt/err.h>
34
35#include <errno.h>
36#include <sys/utsname.h>
37
38
39RTDECL(int) RTSystemQueryOSInfo(RTSYSOSINFO enmInfo, char *pszInfo, size_t cchInfo)
40{
41 /*
42 * Quick validation.
43 */
44 AssertReturn(enmInfo > RTSYSOSINFO_INVALID && enmInfo < RTSYSOSINFO_END, VERR_INVALID_PARAMETER);
45 AssertPtrReturn(pszInfo, VERR_INVALID_POINTER);
46 if (!cchInfo)
47 return VERR_BUFFER_OVERFLOW;
48
49 /*
50 * Handle the request.
51 */
52 switch (enmInfo)
53 {
54 case RTSYSOSINFO_PRODUCT:
55 case RTSYSOSINFO_RELEASE:
56 case RTSYSOSINFO_VERSION:
57 {
58 struct utsname UtsInfo;
59 if (uname(&UtsInfo) < 0)
60 return RTErrConvertFromErrno(errno);
61 const char *pszSrc;
62 switch (enmInfo)
63 {
64 case RTSYSOSINFO_PRODUCT: pszSrc = UtsInfo.sysname; break;
65 case RTSYSOSINFO_RELEASE: pszSrc = UtsInfo.release; break;
66 case RTSYSOSINFO_VERSION: pszSrc = UtsInfo.version; break;
67 default: AssertFatalFailed(); /* screw gcc */
68 }
69 size_t cch = strlen(pszSrc);
70 if (cch < cchInfo)
71 {
72 memcpy(pszInfo, pszSrc, cch + 1);
73 return VINF_SUCCESS;
74 }
75 memcpy(pszInfo, pszSrc, cchInfo - 1);
76 pszInfo[cchInfo - 1] = '\0';
77 return VERR_BUFFER_OVERFLOW;
78 }
79
80
81 case RTSYSOSINFO_SERVICE_PACK:
82 default:
83 *pszInfo = '\0';
84 return VERR_NOT_SUPPORTED;
85 }
86
87 return VINF_SUCCESS;
88}
89
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