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 <stdlib.h>
19 #include "functionalext.h"
20
21 const int32_t CREAT_MODE = 666;
22
23 /**
24 * @tc.name : rewind_0100
25 * @tc.desc : Verify rewind process success
26 * @tc.level : Level 0
27 */
rewind_0100(void)28 void rewind_0100(void)
29 {
30 int32_t ret = creat("/data/rewind_0100.txt", CREAT_MODE);
31 if (ret < 0) {
32 EXPECT_MT("rewind_0100", ret, 0);
33 return;
34 }
35
36 FILE *fptr = fopen("/data/rewind_0100.txt", "w");
37 EXPECT_PTRNE("rewind_0100", fptr, NULL);
38 char str[] = "test";
39 fwrite(str, 1, sizeof(str), fptr);
40 ret = fclose(fptr);
41 EXPECT_EQ("rewind_0100", ret, 0);
42
43 fptr = fopen("/data/rewind_0100.txt", "r");
44 EXPECT_PTRNE("rewind_0100", fptr, NULL);
45 int ch;
46 while ( (ch = fgetc(fptr)) != EOF ){
47 break;
48 }
49
50 rewind(fptr);
51 EXPECT_FALSE("rewind_0100", feof(fptr));
52 fclose(fptr);
53 remove("/data/rewind_0100.txt");
54 }
55
main(void)56 int main(void)
57 {
58 rewind_0100();
59 return t_status;
60 }
61