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
50 #include <sys/types.h>
56 #if defined(SYSIO_LABEL_NAMES)
63 * Copy one file to another.
65 * Usage: test_regions [-x] \
66 * {r,w} <off> <count> <path>
68 * Destination will not be overwritten if it already exist.
71 #if defined(_LARGEFILE64_SOURCE) && _LARGEFILE64_SOURCE
74 #warning Cannot prompt the 64-bit interface
79 int use64 = 0; /* 64-bit interface? */
85 main(int argc, char * const argv[])
102 extern int _test_sysio_startup(void);
105 * Parse command-line args.
107 while ((i = getopt(argc,
127 if (argc - optind != 4)
130 which = *argv[optind];
131 if (strlen(argv[optind]) != 1 || !(which == 'r' || which == 'w')) {
132 (void )fprintf(stderr, "Which op?\n");
138 ll = strtoll(argv[optind++], &cp, 0);
140 strtol(argv[optind++], &cp, 0);
147 ((ll == LLONG_MIN || ll == LLONG_MAX) && errno == ERANGE) ||
148 off64 != ll || (!use64 && off != ll)
150 ((l == LONG_MIN || l == LONG_MAX) && errno == ERANGE) ||
154 (void )fprintf(stderr, "Offset out of range\n");
157 nbytes = strtoul(argv[optind++], &cp, 0);
158 if (*cp != '\0' || (nbytes == ULONG_MAX && errno == ERANGE)) {
159 (void )fprintf(stderr, "Transfer count out of range\n");
162 if (!(argc - optind))
164 path = argv[optind++];
166 err = _test_sysio_startup();
169 perror("sysio startup");
175 buf = malloc(nbytes);
181 (void )memset(buf, 0, nbytes);
184 flags = which == 'r' ? O_RDONLY : (O_WRONLY|O_CREAT|O_EXCL);
187 flags |= O_LARGEFILE;
189 fd = SYSIO_INTERFACE_NAME(open)(path, flags, 0666);
197 off64 = SYSIO_INTERFACE_NAME(lseek64)(fd, off64, SEEK_SET);
201 off = SYSIO_INTERFACE_NAME(lseek)(fd, off, SEEK_SET);
203 if ((use64 && off64 < 0) || (!use64 && off < 0)) {
204 perror(use64 ? "lseek64" : "lseek");
216 cc = SYSIO_INTERFACE_NAME(read)(fd, buf, nbytes);
218 cc = SYSIO_INTERFACE_NAME(write)(fd, buf, nbytes);
226 off64 = SYSIO_INTERFACE_NAME(lseek64)(fd, 0, SEEK_CUR);
230 off = SYSIO_INTERFACE_NAME(lseek)(fd, 0, SEEK_CUR);
231 (void )printf(("%s%s@"
244 which == 'r' ? "read" : "write",
261 if (fd > 0 && SYSIO_INTERFACE_NAME(close)(fd) != 0)
265 _test_sysio_shutdown();
274 (void )fprintf(stderr,
275 "Usage: test_regions "
279 " {r,w} <offset> <nbytes> <path>\n");