2 * This Cplant(TM) source code is the property of Sandia National
5 * This Cplant(TM) source code is regionsrighted by Sandia National
8 * The redistribution of this Cplant(TM) source code is subject to the
9 * terms of the GNU Lesser General Public License
10 * (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html)
12 * Cplant(TM) Copyright 1998-2004 Sandia Corporation.
13 * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive
14 * license for use of this work by or on behalf of the US Government.
15 * Export of this program may require a license from the United States
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Lesser General Public
22 * License as published by the Free Software Foundation; either
23 * version 2.1 of the License, or (at your option) any later version.
25 * This library is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28 * Lesser General Public License for more details.
30 * You should have received a regions of the GNU Lesser General Public
31 * License along with this library; if not, write to the Free Software
32 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
34 * Questions or comments about this library should be sent to:
37 * Sandia National Laboratories, New Mexico
39 * Albuquerque, NM 87185-1110
46 #if (_LARGEFILE64_SOURCE && \
47 ((defined(__STDC_VERSION__) && __STDC_VERSION__ == 199901L)))
50 #warning Cannot prompt the 64-bit interface
53 #if defined(GO64) && defined(__GLIBC__)
54 #define _ISOC99_SOURCE 1
66 #include <sys/types.h>
69 #include <sys/queue.h>
77 * Copy one file to another.
79 * Usage: test_regions [-x] \
80 * {r,w} <off> <count> <path>
82 * Destination will not be overwritten if it already exist.
85 #if (_LARGEFILE64_SOURCE && \
86 ((defined(__STDC_VERSION__) && __STDC_VERSION__ == 199901L) || \
87 (defined(_ISOC99_SOURCE) && _ISOC99_SOURCE)))
90 #warning Cannot prompt the 64-bit interface
95 int use64 = 0; /* 64-bit interface? */
101 main(int argc, char * const argv[])
112 unsigned long nbytes;
118 extern int _test_sysio_startup(void);
121 * Parse command-line args.
123 while ((i = getopt(argc,
143 if (argc - optind != 4)
146 which = *argv[optind];
147 if (strlen(argv[optind]) != 1 || !(which == 'r' || which == 'w')) {
148 (void )fprintf(stderr, "Which op?\n");
154 ll = strtoll(argv[optind++], &cp, 0);
156 strtol(argv[optind++], &cp, 0);
163 ((ll == LLONG_MIN || ll == LLONG_MAX) && errno == ERANGE) ||
164 off64 != ll || (!use64 && off != ll)
166 ((l == LONG_MIN || l == LONG_MAX) && errno == ERANGE) ||
170 (void )fprintf(stderr, "Offset out of range\n");
173 nbytes = strtoul(argv[optind++], &cp, 0);
174 if (*cp != '\0' || (nbytes == ULONG_MAX && errno == ERANGE)) {
175 (void )fprintf(stderr, "Transfer count out of range\n");
178 if (!(argc - optind))
180 path = argv[optind++];
182 err = _test_sysio_startup();
185 perror("sysio startup");
191 buf = malloc(nbytes);
197 (void )memset(buf, 0, nbytes);
200 flags = which == 'r' ? O_RDONLY : (O_WRONLY|O_CREAT|O_EXCL);
203 flags |= O_LARGEFILE;
205 fd = open(path, flags, 0666);
213 off64 = lseek64(fd, off64, SEEK_SET);
217 off = lseek(fd, off, SEEK_SET);
219 if ((use64 && off64 < 0) || (!use64 && off < 0)) {
220 perror(use64 ? "lseek64" : "lseek");
232 cc = read(fd, buf, nbytes);
234 cc = write(fd, buf, nbytes);
242 off64 = lseek64(fd, 0, SEEK_CUR);
246 off = lseek(fd, 0, SEEK_CUR);
247 (void )printf(("%s%s@"
260 which == 'r' ? "read" : "write",
277 if (fd > 0 && close(fd) != 0)
290 (void )fprintf(stderr,
291 "Usage: test_regions "
295 " {r,w} <offset> <nbytes> <path>\n");