* sysdeps/m68k/fpu/bits/mathinline.h: Don't define log2 as inline.
[glibc.git] / io / test-lfs.c
blobdb17db296644e7be9cbe5bb1dfdd41022c81edbb
1 /* Some basic tests for LFS.
2 Copyright (C) 2000, 2001 Free Software Foundation, Inc.
3 Contributed by Andreas Jaeger <aj@suse.de>, 2000.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 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 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
20 #include <unistd.h>
21 #include <stdlib.h>
22 #include <sys/types.h>
23 #include <sys/stat.h>
24 #include <fcntl.h>
25 #include <error.h>
26 #include <errno.h>
27 #include <sys/resource.h>
29 /* Prototype for our test function. */
30 extern void do_prepare (int argc, char *argv[]);
31 extern int do_test (int argc, char *argv[]);
33 /* We have a preparation function. */
34 #define PREPARE do_prepare
36 /* We might need a bit longer timeout. */
37 #define TIMEOUT 20 /* sec */
39 /* This defines the `main' function and some more. */
40 #include <test-skeleton.c>
42 /* These are for the temporary file we generate. */
43 char *name;
44 int fd;
46 /* 2^31 = 2GB. */
47 #define TWO_GB 2147483648LL
49 void
50 do_prepare (int argc, char *argv[])
52 char name_len;
53 struct rlimit64 rlim;
55 name_len = strlen (test_dir);
56 name = malloc (name_len + sizeof ("/lfsXXXXXX"));
57 mempcpy (mempcpy (name, test_dir, name_len),
58 "/lfsXXXXXX", sizeof ("/lfsXXXXXX"));
59 add_temp_file (name);
61 /* Open our test file. */
62 fd = mkstemp64 (name);
63 if (fd == -1)
65 if (errno == ENOSYS)
67 /* Fail silently. */
68 error (0, 0, "open64 is not supported");
69 exit (EXIT_SUCCESS);
71 else
72 error (EXIT_FAILURE, errno, "cannot create temporary file");
75 if (getrlimit64 (RLIMIT_FSIZE, &rlim) != 0)
77 error (0, errno, "cannot get resource limit");
78 exit (0);
80 if (rlim.rlim_cur < TWO_GB + 200)
82 rlim.rlim_cur = TWO_GB + 200;
83 if (setrlimit64 (RLIMIT_FSIZE, &rlim) != 0)
85 error (0, errno, "cannot reset file size limits");
86 exit (0);
91 static void
92 test_ftello (void)
94 FILE *f;
95 int ret;
96 off64_t pos;
98 f = fopen64 (name, "w");
100 ret = fseeko64 (f, TWO_GB+100, SEEK_SET);
101 if (ret == -1 && errno == ENOSYS)
103 error (0, 0, "fseeko64 is not supported.");
104 exit (EXIT_SUCCESS);
106 if (ret == -1 && errno == EINVAL)
108 error (0, 0, "LFS seems not to be supported");
109 exit (EXIT_SUCCESS);
111 if (ret == -1)
113 error (0, errno, "fseeko64 failed with error");
114 exit (EXIT_FAILURE);
117 ret = fwrite ("Hello", 1, 5, f);
118 if (ret == -1 && errno == EFBIG)
120 error (0, errno, "LFS seems not to be supported");
121 exit (EXIT_SUCCESS);
124 if (ret == -1 && errno == ENOSPC)
126 error (0, 0, "Not enough space to write file.");
127 exit (EXIT_SUCCESS);
130 if (ret != 5)
131 error (EXIT_FAILURE, errno, "Cannot write test string to large file");
133 pos = ftello64 (f);
135 if (pos != TWO_GB+105)
137 error (0, 0, "ftello64 gives wrong result.");
138 exit (EXIT_FAILURE);
141 fclose (f);
145 do_test (int argc, char *argv[])
147 int ret;
148 struct stat64 statbuf;
150 ret = lseek64 (fd, TWO_GB+100, SEEK_SET);
151 if (ret == -1 && errno == ENOSYS)
153 error (0, 0, "lseek64 is not supported.");
154 exit (EXIT_SUCCESS);
156 if (ret == -1 && errno == EINVAL)
158 error (0, 0, "LFS seems not to be supported.");
159 exit (EXIT_SUCCESS);
161 if (ret == -1)
163 error (0, errno, "lseek64 failed with error");
164 exit (EXIT_FAILURE);
167 ret = write (fd, "Hello", 5);
168 if (ret == -1 && errno == EFBIG)
170 error (0, 0, "LFS seems not to be supported.");
171 exit (EXIT_SUCCESS);
174 if (ret == -1 && errno == ENOSPC)
176 error (0, 0, "Not enough space to write file.");
177 exit (EXIT_SUCCESS);
180 if (ret != 5)
181 error (EXIT_FAILURE, errno, "cannot write test string to large file");
183 ret = close (fd);
185 if (ret == -1)
186 error (EXIT_FAILURE, errno, "error closing file");
188 ret = stat64 (name, &statbuf);
190 if (ret == -1 && (errno == ENOSYS || errno == EOVERFLOW))
191 error (0, 0, "stat64 is not supported.");
192 else if (ret == -1)
193 error (EXIT_FAILURE, errno, "cannot stat file `%s'", name);
194 else if (statbuf.st_size != (TWO_GB + 100 + 5))
195 error (EXIT_FAILURE, 0, "stat reported size %lld instead of %lld.",
196 (long long int) statbuf.st_size, (TWO_GB + 100 + 5));
198 test_ftello ();
200 return 0;