Home | History | Annotate | Download | only in native
      1 /*
      2  * Copyright (C) 2009 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #include "sieb.h"
     18 #include "JNIHelp.h"
     19 #include "jni.h"
     20 
     21 #include <stdlib.h>
     22 
     23 // Throw java.lang.OutOfMemoryError
     24 void throwNewOutOfMemoryError(JNIEnv *env, const char *message) {
     25     jniThrowException(env, "java/lang/OutOfMemoryError", message);
     26 }
     27 
     28 void *sieb_malloc(JNIEnv *env, size_t byteCnt) {
     29     void *adr = malloc(byteCnt);
     30     if (adr == 0) {
     31         if (byteCnt == 0) {
     32             throwNewOutOfMemoryError(env, "sieb_malloc(0) NOT ALLOWED");
     33         } else {
     34             throwNewOutOfMemoryError(env, "sieb_malloc");
     35         }
     36     }
     37     return adr;
     38 }
     39 
     40 void sieb_free(JNIEnv *env, void *adr) {
     41     free(adr);
     42 }
     43 
     44 void sieb_convertToPlatform(char *path) {
     45     char *pathIndex;
     46 
     47     pathIndex = path;
     48     while (*pathIndex != '\0') {
     49         if (*pathIndex == '\\') {
     50             *pathIndex = '/';
     51         }
     52         pathIndex++;
     53     }
     54 }
     55