• 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 <fcntl.h>
18 
19 #include "filepath_util.h"
20 
21 /**
22  * @tc.name      : unlinkat_0100
23  * @tc.desc      : delete a name and possibly the file it refers to
24  * @tc.level     : Level 0
25  */
unlinkat_0100(void)26 void unlinkat_0100(void)
27 {
28     char path[PATH_MAX] = {0};
29     FILE_ABSOLUTE_PATH(STR_FILE_TXT, path);
30     int fd = open(path, O_CREAT, 0664);
31 
32     int result = unlinkat(fd, path, 0);
33     if (result != 0) {
34         t_error("%s failed: result = %d\n", __func__, result);
35     }
36 
37     close(fd);
38 }
39 
40 /**
41  * @tc.name      : unlinkat_0200
42  * @tc.desc      : delete a name and possibly the file it refers to with AT_REMOVEDIR flag
43  * @tc.level     : Level 2
44  */
unlinkat_0200(void)45 void unlinkat_0200(void)
46 {
47     errno = 0;
48     char path[PATH_MAX] = {0};
49     FILE_ABSOLUTE_PATH(STR_FILE_TXT, path);
50     int result = unlinkat(AT_FDCWD, path, AT_REMOVEDIR);
51     if (result == 0) {
52         t_error("%s failed: result = %d\n", __func__, result);
53     }
54 
55     if (errno != ENOENT) {
56         t_error("%s failed: errno = %d\n", __func__, errno);
57     }
58 }
59 
main(int argc,char * argv[])60 int main(int argc, char *argv[])
61 {
62     unlinkat_0100();
63     unlinkat_0200();
64 
65     return t_status;
66 }
67