test pwrite

Link to this paste: http://bugs.dragonflybsd.org/pastes/405

Added by tuxillo about 2 years ago.
Syntax: C

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
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
#include <err.h>

int
main(int argc, char *argv[])
{

        int n, fd;
        char buf[1024];
        size_t size;

        if (argc == 2) {
                size = strtol(argv[1], NULL, 0);
                printf("Size is %d\n", size);
        }


        fd = open("/dev/vkd1s1a", O_RDWR);
        if (fd < 0)
                perror("open");

        n = pwrite(fd, buf, size, 0);
        if (n == -1)
                err(1, "pwrite failed");

        printf("%d\n", n);
}

Download