• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
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 <errno.h>
17 #include <pwd.h>
18 #include <stdio.h>
19 #include <string.h>
20 
21 #include "test.h"
22 
23 /**
24  * @tc.name      : setpwent_0100
25  * @tc.desc      : rewinds to the beginning of the password database
26  * @tc.level     : Level 0
27  */
setpwent_0100(void)28 void setpwent_0100(void)
29 {
30     errno = 0;
31     struct passwd *result = getpwent();
32     if (result == NULL) {
33         t_error("%s failed: getpwent\n", __func__);
34     }
35 
36     if (errno != 0) {
37         t_error("%s failed: getpwent. errno = %ld\n", __func__, errno);
38     }
39 
40     char buf[BUFSIZ] = {0};
41     strcpy(buf, result->pw_name);
42 
43     setpwent();
44 
45     result = getpwent();
46     if (result == NULL) {
47         t_error("%s failed: getpwent\n", __func__);
48     }
49 
50     if (strcmp(result->pw_name, buf)) {
51         t_error("%s failed: result->pw_name = %s\n", __func__, result->pw_name);
52     }
53 }
54 
main(int argc,char * argv[])55 int main(int argc, char *argv[])
56 {
57     setpwent_0100();
58 
59     return t_status;
60 }
61