1f08c3bdfSopenharmony_ci/* 2f08c3bdfSopenharmony_ci * Cygwin Compatibility functions 3f08c3bdfSopenharmony_ci * 4f08c3bdfSopenharmony_ci * 5f08c3bdfSopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a copy 6f08c3bdfSopenharmony_ci * of this software and associated documentation files (the "Software"), to deal 7f08c3bdfSopenharmony_ci * in the Software without restriction, including without limitation the rights 8f08c3bdfSopenharmony_ci * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9f08c3bdfSopenharmony_ci * copies of the Software, and to permit persons to whom the Software is 10f08c3bdfSopenharmony_ci * furnished to do so, subject to the following conditions: 11f08c3bdfSopenharmony_ci * 12f08c3bdfSopenharmony_ci * The above copyright notice and this permission notice shall be included in 13f08c3bdfSopenharmony_ci * all copies or substantial portions of the Software. 14f08c3bdfSopenharmony_ci * 15f08c3bdfSopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16f08c3bdfSopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17f08c3bdfSopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18f08c3bdfSopenharmony_ci * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19f08c3bdfSopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20f08c3bdfSopenharmony_ci * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21f08c3bdfSopenharmony_ci * THE SOFTWARE. 22f08c3bdfSopenharmony_ci */ 23f08c3bdfSopenharmony_ci 24f08c3bdfSopenharmony_ci 25f08c3bdfSopenharmony_ci 26f08c3bdfSopenharmony_ci#include <sys/mman.h> 27f08c3bdfSopenharmony_ci#include <stdlib.h> 28f08c3bdfSopenharmony_ci#include <string.h> 29f08c3bdfSopenharmony_ci#include <sys/stat.h> 30f08c3bdfSopenharmony_ci 31f08c3bdfSopenharmony_ci#include "lib.h" 32f08c3bdfSopenharmony_ci#include "allocate.h" 33f08c3bdfSopenharmony_ci#include "token.h" 34f08c3bdfSopenharmony_ci 35f08c3bdfSopenharmony_civoid *blob_alloc(unsigned long size) 36f08c3bdfSopenharmony_ci{ 37f08c3bdfSopenharmony_ci void *ptr; 38f08c3bdfSopenharmony_ci size = (size + 4095) & ~4095; 39f08c3bdfSopenharmony_ci ptr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); 40f08c3bdfSopenharmony_ci if (ptr == MAP_FAILED) 41f08c3bdfSopenharmony_ci ptr = NULL; 42f08c3bdfSopenharmony_ci else 43f08c3bdfSopenharmony_ci memset(ptr, 0, size); 44f08c3bdfSopenharmony_ci return ptr; 45f08c3bdfSopenharmony_ci} 46f08c3bdfSopenharmony_ci 47f08c3bdfSopenharmony_civoid blob_free(void *addr, unsigned long size) 48f08c3bdfSopenharmony_ci{ 49f08c3bdfSopenharmony_ci size = (size + 4095) & ~4095; 50f08c3bdfSopenharmony_ci munmap(addr, size); 51f08c3bdfSopenharmony_ci} 52f08c3bdfSopenharmony_ci 53f08c3bdfSopenharmony_cilong double string_to_ld(const char *nptr, char **endptr) 54f08c3bdfSopenharmony_ci{ 55f08c3bdfSopenharmony_ci return strtod(nptr, endptr); 56f08c3bdfSopenharmony_ci} 57