1 | // RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s |
2 | // |
3 | // UNSUPPORTED: darwin, target={{.*(linux|solaris).*}} |
4 | |
5 | #include <assert.h> |
6 | #include <inttypes.h> |
7 | #include <stdio.h> |
8 | |
9 | int main(void) { |
10 | printf(format: "fseek\n" ); |
11 | |
12 | FILE *fp = fopen(filename: "/etc/fstab" , modes: "r" ); |
13 | assert(fp); |
14 | |
15 | int rv = fseek(stream: fp, off: 10, SEEK_SET); |
16 | assert(!rv); |
17 | |
18 | printf(format: "position: %ld\n" , ftell(stream: fp)); |
19 | |
20 | rewind(stream: fp); |
21 | |
22 | printf(format: "position: %ld\n" , ftell(stream: fp)); |
23 | |
24 | rv = fseeko(stream: fp, off: 15, SEEK_SET); |
25 | assert(!rv); |
26 | |
27 | printf(format: "position: %" PRIuMAX "\n" , (uintmax_t)ftello(stream: fp)); |
28 | |
29 | fpos_t pos; |
30 | rv = fgetpos(stream: fp, pos: &pos); |
31 | assert(!rv); |
32 | |
33 | rewind(stream: fp); |
34 | |
35 | printf(format: "position: %" PRIuMAX "\n" , (uintmax_t)ftello(stream: fp)); |
36 | |
37 | rv = fsetpos(stream: fp, pos: &pos); |
38 | assert(!rv); |
39 | |
40 | printf(format: "position: %" PRIuMAX "\n" , (uintmax_t)ftello(stream: fp)); |
41 | |
42 | rv = fclose(stream: fp); |
43 | assert(!rv); |
44 | |
45 | // CHECK: fseek |
46 | // CHECK: position: 10 |
47 | // CHECK: position: 0 |
48 | // CHECK: position: 15 |
49 | // CHECK: position: 0 |
50 | // CHECK: position: 15 |
51 | |
52 | return 0; |
53 | } |
54 | |