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 <fcntl.h>
17 #include <stdio.h>
18 #include <string.h>
19 #include <sys/xattr.h>
20 #include "test.h"
21
22 /**
23 * @tc.name : fgetxattr_0100
24 * @tc.desc : Verify that the extended attribute value can be obtained.
25 * @tc.level : Level 0
26 */
fgetxattr_0100(void)27 void fgetxattr_0100(void)
28 {
29 const char *path = "/data/fgetxattr.txt";
30 char name[] = "user.x";
31 char value[] = "the past is not dead.";
32
33 int fd = open(path, O_RDWR | O_CREAT, TEST_MODE);
34 if (fd < 0) {
35 t_error("%s open failed\n", __func__);
36 }
37
38 int ret = fsetxattr(fd, name, value, strlen(value), 0);
39 if (ret != 0) {
40 t_error("%s fsetxattr failed\n", __func__);
41 }
42
43 ssize_t result = fgetxattr(fd, name, value, 1024);
44 if (result < 0) {
45 t_error("%s fgetxattr failed\n", __func__);
46 }
47
48 close(fd);
49 remove(path);
50 }
51
main(int argc, char *argv[])52 int main(int argc, char *argv[])
53 {
54 fgetxattr_0100();
55 return t_status;
56 }
57