< prev index next >

src/java.base/share/native/libjava/io_util.h

Print this page




  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
  23  * questions.
  24  */
  25 
  26 #include "jni.h"
  27 #include "jni_util.h"
  28 
  29 extern jfieldID IO_fd_fdID;
  30 extern jfieldID IO_handle_fdID;
  31 extern jfieldID IO_append_fdID;

  32 
  33 #ifdef _ALLBSD_SOURCE
  34 #include <fcntl.h>
  35 #ifndef O_SYNC
  36 #define O_SYNC  O_FSYNC
  37 #endif
  38 #ifndef O_DSYNC
  39 #define O_DSYNC O_FSYNC
  40 #endif
  41 #elif !defined(O_DSYNC) || !defined(O_SYNC)
  42 #define O_SYNC  (0x0800)
  43 #define O_DSYNC (0x2000)
  44 #endif
  45 
  46 /*
  47  * IO helper functions
  48  */
  49 
  50 jint readSingle(JNIEnv *env, jobject this, jfieldID fid);
  51 jint readBytes(JNIEnv *env, jobject this, jbyteArray bytes, jint off,
  52                jint len, jfieldID fid);


  53 void writeSingle(JNIEnv *env, jobject this, jint byte, jboolean append, jfieldID fid);
  54 void writeBytes(JNIEnv *env, jobject this, jbyteArray bytes, jint off,
  55                 jint len, jboolean append, jfieldID fid);


  56 void fileOpen(JNIEnv *env, jobject this, jstring path, jfieldID fid, int flags);
  57 void throwFileNotFoundException(JNIEnv *env, jstring path);
  58 
  59 /*
  60  * Macros for managing platform strings.  The typical usage pattern is:
  61  *
  62  *     WITH_PLATFORM_STRING(env, string, var) {
  63  *         doSomethingWith(var);
  64  *     } END_PLATFORM_STRING(env, var);
  65  *
  66  *  where  env      is the prevailing JNIEnv,
  67  *         string   is a JNI reference to a java.lang.String object, and
  68  *         var      is the char * variable that will point to the string,
  69  *                  after being converted into the platform encoding.
  70  *
  71  * The related macro WITH_FIELD_PLATFORM_STRING first extracts the string from
  72  * a given field of a given object:
  73  *
  74  *     WITH_FIELD_PLATFORM_STRING(env, object, id, var) {
  75  *         doSomethingWith(var);


 110 
 111 /* Macros for transforming Java Strings into native Unicode strings.
 112  * Works analogously to WITH_PLATFORM_STRING.
 113  */
 114 
 115 #define WITH_UNICODE_STRING(env, strexp, var)                                 \
 116     if (1) {                                                                  \
 117         const jchar *var;                                                     \
 118         jstring _##var##str = (strexp);                                       \
 119         if (_##var##str == NULL) {                                            \
 120             JNU_ThrowNullPointerException((env), NULL);                       \
 121             goto _##var##end;                                                 \
 122         }                                                                     \
 123         var = (*(env))->GetStringChars((env), _##var##str, NULL);             \
 124         if (var == NULL) goto _##var##end;
 125 
 126 #define END_UNICODE_STRING(env, var)                                          \
 127         (*(env))->ReleaseStringChars(env, _##var##str, var);                  \
 128     _##var##end: ;                                                            \
 129     } else ((void)NULL)





  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
  23  * questions.
  24  */
  25 
  26 #include "jni.h"
  27 #include "jni_util.h"
  28 
  29 extern jfieldID IO_fd_fdID;
  30 extern jfieldID IO_handle_fdID;
  31 extern jfieldID IO_append_fdID;
  32 extern jfieldID IO_pgsz_fdID;
  33 
  34 #ifdef _ALLBSD_SOURCE
  35 #include <fcntl.h>
  36 #ifndef O_SYNC
  37 #define O_SYNC  O_FSYNC
  38 #endif
  39 #ifndef O_DSYNC
  40 #define O_DSYNC O_FSYNC
  41 #endif
  42 #elif !defined(O_DSYNC) || !defined(O_SYNC)
  43 #define O_SYNC  (0x0800)
  44 #define O_DSYNC (0x2000)
  45 #endif
  46 
  47 /*
  48  * IO helper functions
  49  */
  50 
  51 jint readSingle(JNIEnv *env, jobject this, jfieldID fid);
  52 jint readBytes(JNIEnv *env, jobject this, jbyteArray bytes, jint off,
  53                jint len, jfieldID fid);
  54 jint readBytesD(JNIEnv *env, jobject this, jbyteArray bytes, jint off,
  55                jint len, jfieldID fid, jfieldID pgsz_id);
  56 void writeSingle(JNIEnv *env, jobject this, jint byte, jboolean append, jfieldID fid);
  57 void writeBytes(JNIEnv *env, jobject this, jbyteArray bytes, jint off,
  58                 jint len, jboolean append, jfieldID fid);
  59 void writeBytesD(JNIEnv *env, jobject this, jbyteArray bytes, jint off,
  60                 jint len, jboolean append, jfieldID fid, jfieldID pgsz_id);
  61 void fileOpen(JNIEnv *env, jobject this, jstring path, jfieldID fid, int flags);
  62 void throwFileNotFoundException(JNIEnv *env, jstring path);
  63 
  64 /*
  65  * Macros for managing platform strings.  The typical usage pattern is:
  66  *
  67  *     WITH_PLATFORM_STRING(env, string, var) {
  68  *         doSomethingWith(var);
  69  *     } END_PLATFORM_STRING(env, var);
  70  *
  71  *  where  env      is the prevailing JNIEnv,
  72  *         string   is a JNI reference to a java.lang.String object, and
  73  *         var      is the char * variable that will point to the string,
  74  *                  after being converted into the platform encoding.
  75  *
  76  * The related macro WITH_FIELD_PLATFORM_STRING first extracts the string from
  77  * a given field of a given object:
  78  *
  79  *     WITH_FIELD_PLATFORM_STRING(env, object, id, var) {
  80  *         doSomethingWith(var);


 115 
 116 /* Macros for transforming Java Strings into native Unicode strings.
 117  * Works analogously to WITH_PLATFORM_STRING.
 118  */
 119 
 120 #define WITH_UNICODE_STRING(env, strexp, var)                                 \
 121     if (1) {                                                                  \
 122         const jchar *var;                                                     \
 123         jstring _##var##str = (strexp);                                       \
 124         if (_##var##str == NULL) {                                            \
 125             JNU_ThrowNullPointerException((env), NULL);                       \
 126             goto _##var##end;                                                 \
 127         }                                                                     \
 128         var = (*(env))->GetStringChars((env), _##var##str, NULL);             \
 129         if (var == NULL) goto _##var##end;
 130 
 131 #define END_UNICODE_STRING(env, var)                                          \
 132         (*(env))->ReleaseStringChars(env, _##var##str, var);                  \
 133     _##var##end: ;                                                            \
 134     } else ((void)NULL)
 135 
 136 #define GET_PG_SIZE(this, IO_pgsz_fdID) \
 137         (*env)->GetIntField(env, (this), (IO_pgsz_fdID))
< prev index next >