1 | /* $Id: RTSystemQueryOSInfo-posix.cpp 15850 2009-01-08 10:16:09Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT - RTSystemQueryOSInfo, POSIX implementation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2008 Sun Microsystems, Inc.
|
---|
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 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
27 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
28 | * additional information or have any questions.
|
---|
29 | */
|
---|
30 |
|
---|
31 | /*******************************************************************************
|
---|
32 | * Header Files *
|
---|
33 | *******************************************************************************/
|
---|
34 | #include <iprt/system.h>
|
---|
35 | #include <iprt/assert.h>
|
---|
36 | #include <iprt/string.h>
|
---|
37 | #include <iprt/err.h>
|
---|
38 |
|
---|
39 | #include <errno.h>
|
---|
40 | #include <sys/utsname.h>
|
---|
41 |
|
---|
42 |
|
---|
43 | RTDECL(int) RTSystemQueryOSInfo(RTSYSOSINFO enmInfo, char *pszInfo, size_t cchInfo)
|
---|
44 | {
|
---|
45 | /*
|
---|
46 | * Quick validation.
|
---|
47 | */
|
---|
48 | AssertReturn(enmInfo > RTSYSOSINFO_INVALID && enmInfo < RTSYSOSINFO_END, VERR_INVALID_PARAMETER);
|
---|
49 | AssertPtrReturn(pszInfo, VERR_INVALID_POINTER);
|
---|
50 | if (!cchInfo)
|
---|
51 | return VERR_BUFFER_OVERFLOW;
|
---|
52 |
|
---|
53 | /*
|
---|
54 | * Handle the request.
|
---|
55 | */
|
---|
56 | switch (enmInfo)
|
---|
57 | {
|
---|
58 | case RTSYSOSINFO_PRODUCT:
|
---|
59 | case RTSYSOSINFO_RELEASE:
|
---|
60 | case RTSYSOSINFO_VERSION:
|
---|
61 | {
|
---|
62 | struct utsname UtsInfo;
|
---|
63 | if (uname(&UtsInfo) < 0)
|
---|
64 | return RTErrConvertFromErrno(errno);
|
---|
65 | const char *pszSrc;
|
---|
66 | switch (enmInfo)
|
---|
67 | {
|
---|
68 | case RTSYSOSINFO_PRODUCT: pszSrc = UtsInfo.sysname; break;
|
---|
69 | case RTSYSOSINFO_RELEASE: pszSrc = UtsInfo.release; break;
|
---|
70 | case RTSYSOSINFO_VERSION: pszSrc = UtsInfo.version; break;
|
---|
71 | default: AssertFatalFailed(); /* screw gcc */
|
---|
72 | }
|
---|
73 | size_t cch = strlen(pszSrc);
|
---|
74 | if (cch < cchInfo)
|
---|
75 | {
|
---|
76 | memcpy(pszInfo, pszSrc, cch + 1);
|
---|
77 | return VINF_SUCCESS;
|
---|
78 | }
|
---|
79 | memcpy(pszInfo, pszSrc, cchInfo - 1);
|
---|
80 | pszInfo[cchInfo - 1] = '\0';
|
---|
81 | return VERR_BUFFER_OVERFLOW;
|
---|
82 | }
|
---|
83 |
|
---|
84 |
|
---|
85 | case RTSYSOSINFO_SERVICE_PACK:
|
---|
86 | default:
|
---|
87 | *pszInfo = '\0';
|
---|
88 | return VERR_NOT_SUPPORTED;
|
---|
89 | }
|
---|
90 |
|
---|
91 | return VINF_SUCCESS;
|
---|
92 | }
|
---|
93 |
|
---|