1 /* 2 * Copyright (c) Huawei Technologies Co., Ltd. 2020-2023. All rights reserved. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include "grp.h" 17 #include "pwd.h" 18 #include "util.h" 19 #if defined __APPLE__ 20 #include <sys/types.h> 21 #include <unistd.h> 22 #endif 23 24 using namespace std; 25 26 constexpr int NGROUPS = 64; 27 Bm_function_Getgrouplist(benchmark::State & state)28static void Bm_function_Getgrouplist(benchmark::State &state) 29 { 30 const char *user = "root"; 31 struct passwd *pw = getpwnam(user); 32 if (pw == nullptr) { 33 perror("getpwnam"); 34 } 35 36 #if defined __APPLE__ 37 int groups[NGROUPS]; 38 #else 39 gid_t groups[NGROUPS]; 40 #endif 41 for (auto _ : state) { 42 int ngroups = NGROUPS; 43 benchmark::DoNotOptimize(getgrouplist(user, pw->pw_gid, groups, &ngroups)); 44 } 45 } 46 47 MUSL_BENCHMARK(Bm_function_Getgrouplist); 48