• 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 <dirent.h>
17 #include <signal.h>
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include "test.h"
21 
22 const char *path = "/data";
23 
handler(int sig)24 void handler(int sig)
25 {
26     exit(t_status);
27 }
28 
29 /**
30  * @tc.name      : telldir_0100
31  * @tc.desc      : Get the current read position of the parameter dir directory stream
32  * @tc.level     : Level 0
33  */
telldir_0100(void)34 void telldir_0100(void)
35 {
36     DIR *dir;
37     struct dirent *ptr;
38     int counter = 0;
39     dir = opendir(path);
40     long offset1 = telldir(dir);
41     long offset2 = 0;
42     while ((ptr = readdir(dir)) != NULL) {
43         counter++;
44 
45         if (counter > 1) {
46             offset2 = telldir(dir);
47             break;
48         }
49     }
50     if (offset1 == offset2) {
51         t_error("%s offset2 invalid", __func__);
52     }
53     closedir(dir);
54 }
55 
56 /**
57  * @tc.name      : telldir_0200
58  * @tc.desc      : Catch exception when parameter dir is NULL
59  * @tc.level     : Level 2
60  */
telldir_0200(void)61 void telldir_0200(void)
62 {
63     signal(SIGSEGV, handler);
64 
65     DIR *dir = NULL;
66     telldir(dir);
67 }
68 
main(int argc,char * argv[])69 int main(int argc, char *argv[])
70 {
71     telldir_0100();
72     telldir_0200();
73     return t_status;
74 }
75