File: ftruncate.c

package info (click to toggle)
glusterfs 9.2-1
  • links: PTS
  • area: main
  • in suites: bullseye
  • size: 44,016 kB
  • sloc: ansic: 478,310; sh: 49,170; python: 12,964; makefile: 1,945; yacc: 487; lisp: 124; lex: 61; xml: 14
file content (34 lines) | stat: -rw-r--r-- 567 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include <fcntl.h>

int
main(int argc, char **argv)
{
    int pfd;

    pfd = open(argv[1], O_RDWR);
    if (pfd == (-1)) {
        perror("open");
        return EXIT_FAILURE;
    }

    if (ftruncate(pfd, 0) == (-1)) {
        perror("ftruncate");
        return EXIT_FAILURE;
    }

    if (write(pfd, "hello", 5) == (-1)) {
        perror("write");
        return EXIT_FAILURE;
    }

    if (fsync(pfd) == (-1)) {
        perror("fsync");
        return EXIT_FAILURE;
    }

    return EXIT_SUCCESS;
}