< prev index next >

src/share/vm/prims/jvm.cpp

Print this page


   1 /*
   2  * Copyright (c) 1997, 2014, 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.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


2857 JVM_LEAF(jint, JVM_SetLength(jint fd, jlong length))
2858   JVMWrapper3("JVM_SetLength (0x%x, " INT64_FORMAT ")", fd, (int64_t) length);
2859   return os::ftruncate(fd, length);
2860 JVM_END
2861 
2862 
2863 JVM_LEAF(jint, JVM_Sync(jint fd))
2864   JVMWrapper2("JVM_Sync (0x%x)", fd);
2865   //%note jvm_r6
2866   return os::fsync(fd);
2867 JVM_END
2868 
2869 
2870 // Printing support //////////////////////////////////////////////////
2871 extern "C" {
2872 
2873 ATTRIBUTE_PRINTF(3, 0)
2874 int jio_vsnprintf(char *str, size_t count, const char *fmt, va_list args) {
2875   // see bug 4399518, 4417214
2876   if ((intptr_t)count <= 0) return -1;
2877   return vsnprintf(str, count, fmt, args);











2878 }
2879 
2880 ATTRIBUTE_PRINTF(3, 0)
2881 int jio_snprintf(char *str, size_t count, const char *fmt, ...) {
2882   va_list args;
2883   int len;
2884   va_start(args, fmt);
2885   len = jio_vsnprintf(str, count, fmt, args);
2886   va_end(args);
2887   return len;
2888 }
2889 
2890 ATTRIBUTE_PRINTF(2,3)
2891 int jio_fprintf(FILE* f, const char *fmt, ...) {
2892   int len;
2893   va_list args;
2894   va_start(args, fmt);
2895   len = jio_vfprintf(f, fmt, args);
2896   va_end(args);
2897   return len;


   1 /*
   2  * Copyright (c) 1997, 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.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


2857 JVM_LEAF(jint, JVM_SetLength(jint fd, jlong length))
2858   JVMWrapper3("JVM_SetLength (0x%x, " INT64_FORMAT ")", fd, (int64_t) length);
2859   return os::ftruncate(fd, length);
2860 JVM_END
2861 
2862 
2863 JVM_LEAF(jint, JVM_Sync(jint fd))
2864   JVMWrapper2("JVM_Sync (0x%x)", fd);
2865   //%note jvm_r6
2866   return os::fsync(fd);
2867 JVM_END
2868 
2869 
2870 // Printing support //////////////////////////////////////////////////
2871 extern "C" {
2872 
2873 ATTRIBUTE_PRINTF(3, 0)
2874 int jio_vsnprintf(char *str, size_t count, const char *fmt, va_list args) {
2875   // see bug 4399518, 4417214
2876   if ((intptr_t)count <= 0) return -1;
2877 
2878   int result = vsnprintf(str, count, fmt, args);
2879   // Note: on truncation vsnprintf(3) on Unix returns number of
2880   // characters which would have been written had the buffer been large
2881   // enough; on Windows, it returns -1. We handle both cases here and
2882   // always return -1, and perform null termination.
2883   if ((result > 0 && (size_t)result >= count) || result == -1) {
2884     str[count - 1] = '\0';
2885     result = -1;
2886   }
2887 
2888   return result;
2889 }
2890 
2891 ATTRIBUTE_PRINTF(3, 0)
2892 int jio_snprintf(char *str, size_t count, const char *fmt, ...) {
2893   va_list args;
2894   int len;
2895   va_start(args, fmt);
2896   len = jio_vsnprintf(str, count, fmt, args);
2897   va_end(args);
2898   return len;
2899 }
2900 
2901 ATTRIBUTE_PRINTF(2,3)
2902 int jio_fprintf(FILE* f, const char *fmt, ...) {
2903   int len;
2904   va_list args;
2905   va_start(args, fmt);
2906   len = jio_vfprintf(f, fmt, args);
2907   va_end(args);
2908   return len;


< prev index next >