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