Debian Codegraph @

madrisan-nagios-plugins-linux/nagios-plugins-linux/tests/tslibuname.c

raw symbols SCIP
1 // SPDX-License-Identifier: GPL-3.0-or-later
2 /*
3 * License: GPLv3+
4 * Copyright (c) 2016 Davide Madrisan <[email protected]>
5 *
6 * Unit test library for checking lib/kernelver.c
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23 #include <string.h>
24 #include <sys/utsname.h>
25
26 #include "testutils.h"
27
28 /*
29 * SUSv3 specifies uname(), but leaves the lengths of the various fields
30 * of the utsname structure undefined, requiring only that the strings be
31 * terminated by a null byte. On Linux, these fields are each 65 bytes
32 * long; including space for terminating null byte.
33 * Glibc declares a variable _UTSNAME_[A-Z]*_LENGTH for each field, all
34 * equal to _UTSNAME_LENGTH which in turn equals to 65.
35 * Musl libc (shipped by Linux Alpine) does not declare any length variable
36 * but hardcodes this value in each field definition.
37 */
38 #if !defined _UTSNAME_RELEASE_LENGTH && defined LIBC_MUSL
39 # define _UTSNAME_RELEASE_LENGTH 65
40 #endif
41
42 int
43 uname (struct utsname *__name)
44 {
45 const char krelease[] = TEST_KERNEL_VERSION;
46 strncpy (__name->release, krelease, _UTSNAME_RELEASE_LENGTH);
47 return 0;
48 }