1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 3 * Copyright (c) 2024 FUJITSU LIMITED. All Rights Reserved. 4 * Author: Yang Xu <[email protected]> 5 */ 6 7 /*\ 8 * [Description] 9 * 10 * Verify that gethostname(2) fails with 11 * 12 * - ENAMETOOLONG when len is smaller than the actual size 13 */ 14 15 #include "tst_test.h" 16 verify_gethostname(void)17static void verify_gethostname(void) 18 { 19 char hostname[HOST_NAME_MAX]; 20 int real_length; 21 22 SAFE_GETHOSTNAME(hostname, sizeof(hostname)); 23 real_length = strlen(hostname); 24 25 TST_EXP_FAIL(gethostname(hostname, real_length - 1), ENAMETOOLONG, 26 "len is smaller than the actual size"); 27 } 28 29 static struct tst_test test = { 30 .test_all = verify_gethostname, 31 }; 32