1 /*
2 * Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
198
199 if ((current = lseek64(fd, 0, SEEK_CUR)) == -1) {
200 return 0;
201 }
202
203 if (size < current) {
204 if ((size = lseek64(fd, 0, SEEK_END)) == -1)
205 return 0;
206 else if (lseek64(fd, current, SEEK_SET) == -1)
207 return 0;
208 }
209
210 *pbytes = size - current;
211 return 1;
212 }
213
214 jint
215 handleSetLength(FD fd, jlong length)
216 {
217 int result;
218 RESTARTABLE(ftruncate64(fd, length), result);
219 return result;
220 }
221
222 jlong
223 handleGetLength(FD fd)
224 {
225 struct stat64 sb;
226 if (fstat64(fd, &sb) == 0) {
227 return sb.st_size;
228 } else {
229 return -1;
230 }
231 }
|
1 /*
2 * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
198
199 if ((current = lseek64(fd, 0, SEEK_CUR)) == -1) {
200 return 0;
201 }
202
203 if (size < current) {
204 if ((size = lseek64(fd, 0, SEEK_END)) == -1)
205 return 0;
206 else if (lseek64(fd, current, SEEK_SET) == -1)
207 return 0;
208 }
209
210 *pbytes = size - current;
211 return 1;
212 }
213
214 jint
215 handleSetLength(FD fd, jlong length)
216 {
217 int result;
218 #if defined(__linux__)
219 /*
220 * On Linux, if the file size is being increased, then ftruncate64()
221 * will modify the metadata value of the size without actually allocating
222 * any blocks which can cause a SIGBUS error if the file is subsequently
223 * memory-mapped.
224 */
225 struct stat64 sb;
226
227 if (fstat64(fd, &sb) == 0 && length > sb.st_blocks*512) {
228 RESTARTABLE(fallocate64(fd, 0, 0, length), result);
229 return result;
230 }
231 #endif
232 RESTARTABLE(ftruncate64(fd, length), result);
233 return result;
234 }
235
236 jlong
237 handleGetLength(FD fd)
238 {
239 struct stat64 sb;
240 if (fstat64(fd, &sb) == 0) {
241 return sb.st_size;
242 } else {
243 return -1;
244 }
245 }
|