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