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
63 #include <sys/types.h>
68 #if defined(SYSIO_LABEL_NAMES)
75 * Copy one file to another.
77 * Usage: test_regions [-x] \
78 * {r,w} <off> <count> <path>
80 * Destination will not be overwritten if it already exist.
83 #if (_LARGEFILE64_SOURCE && \
84 ((defined(__STDC_VERSION__) && __STDC_VERSION__ == 199901L) || \
85 (defined(_ISOC99_SOURCE) && _ISOC99_SOURCE)))
88 #warning Cannot prompt the 64-bit interface
93 int use64 = 0; /* 64-bit interface? */
99 main(int argc, char * const argv[])
110 unsigned long nbytes;
116 extern int _test_sysio_startup(void);
119 * Parse command-line args.
121 while ((i = getopt(argc,
141 if (argc - optind != 4)
144 which = *argv[optind];
145 if (strlen(argv[optind]) != 1 || !(which == 'r' || which == 'w')) {
146 (void )fprintf(stderr, "Which op?\n");
152 ll = strtoll(argv[optind++], &cp, 0);
154 strtol(argv[optind++], &cp, 0);
161 ((ll == LLONG_MIN || ll == LLONG_MAX) && errno == ERANGE) ||
162 off64 != ll || (!use64 && off != ll)
164 ((l == LONG_MIN || l == LONG_MAX) && errno == ERANGE) ||
168 (void )fprintf(stderr, "Offset out of range\n");
171 nbytes = strtoul(argv[optind++], &cp, 0);
172 if (*cp != '\0' || (nbytes == ULONG_MAX && errno == ERANGE)) {
173 (void )fprintf(stderr, "Transfer count out of range\n");
176 if (!(argc - optind))
178 path = argv[optind++];
180 err = _test_sysio_startup();
183 perror("sysio startup");
189 buf = malloc(nbytes);
195 (void )memset(buf, 0, nbytes);
198 flags = which == 'r' ? O_RDONLY : (O_WRONLY|O_CREAT|O_EXCL);
201 flags |= O_LARGEFILE;
203 fd = SYSIO_INTERFACE_NAME(open)(path, flags, 0666);
211 off64 = SYSIO_INTERFACE_NAME(lseek64)(fd, off64, SEEK_SET);
215 off = SYSIO_INTERFACE_NAME(lseek)(fd, off, SEEK_SET);
217 if ((use64 && off64 < 0) || (!use64 && off < 0)) {
218 perror(use64 ? "lseek64" : "lseek");
230 cc = SYSIO_INTERFACE_NAME(read)(fd, buf, nbytes);
232 cc = SYSIO_INTERFACE_NAME(write)(fd, buf, nbytes);
240 off64 = SYSIO_INTERFACE_NAME(lseek64)(fd, 0, SEEK_CUR);
244 off = SYSIO_INTERFACE_NAME(lseek)(fd, 0, SEEK_CUR);
245 (void )printf(("%s%s@"
258 which == 'r' ? "read" : "write",
275 if (fd > 0 && SYSIO_INTERFACE_NAME(close)(fd) != 0)
279 _test_sysio_shutdown();
288 (void )fprintf(stderr,
289 "Usage: test_regions "
293 " {r,w} <offset> <nbytes> <path>\n");