Add femode_t functions: sh.
[glibc.git] / posix / tst-preadwrite-common.c
blob533fb93480cc4f12b8c48420f95abb56250bc355
1 /* Common definitions for pread and pwrite.
2 Copyright (C) 2016 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 #include <errno.h>
20 #include <error.h>
21 #include <string.h>
22 #include <unistd.h>
24 static void do_prepare (void);
25 #define PREPARE(argc, argv) do_prepare ()
26 static int do_test (void);
27 #define TEST_FUNCTION do_test ()
29 /* We might need a bit longer timeout. */
30 #define TIMEOUT 20 /* sec */
32 /* This defines the `main' function and some more. */
33 #include <test-skeleton.c>
35 /* These are for the temporary file we generate. */
36 static char *name;
37 static int fd;
39 static void
40 do_prepare (void)
42 fd = create_temp_file ("tst-preadwrite.", &name);
43 if (fd == -1)
44 error (EXIT_FAILURE, errno, "cannot create temporary file");
48 static ssize_t
49 do_test_with_offset (off_t offset)
51 char buf[1000];
52 char res[1000];
53 int i;
54 ssize_t ret;
56 memset (buf, '\0', sizeof (buf));
57 memset (res, '\xff', sizeof (res));
59 if (write (fd, buf, sizeof (buf)) != sizeof (buf))
60 error (EXIT_FAILURE, errno, "during write");
62 for (i = 100; i < 200; ++i)
63 buf[i] = i;
64 ret = pwrite (fd, buf + 100, 100, offset + 100);
65 if (ret == -1)
66 error (EXIT_FAILURE, errno, "during pwrite");
68 for (i = 450; i < 600; ++i)
69 buf[i] = i;
70 ret = pwrite (fd, buf + 450, 150, offset + 450);
71 if (ret == -1)
72 error (EXIT_FAILURE, errno, "during pwrite");
74 ret = pread (fd, res, sizeof (buf) - 50, offset + 50);
75 if (ret == -1)
76 error (EXIT_FAILURE, errno, "during pread");
78 if (memcmp (buf + 50, res, ret) != 0)
80 printf ("error: read of pread != write of pwrite\n");
81 return -1;
84 return ret;