]>
git.ipfire.org Git - people/ms/u-boot.git/blob - tools/mingw_support.c
2 * Copyright 2008 Extreme Engineering Solutions, Inc.
4 * mmap/munmap implementation derived from:
5 * Clamav Native Windows Port : mmap win32 compatibility layer
6 * Copyright (c) 2005-2006 Gianluigi Tiesi <sherpya@netfarm.it>
7 * Parts by Kees Zeelenberg <kzlg@users.sourceforge.net> (LibGW32C)
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
19 * You should have received a copy of the GNU Library General Public
20 * License along with this software; if not, write to the
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 #include "mingw_support.h"
37 void *mmap(void *addr
, size_t len
, int prot
, int flags
, int fd
, int offset
)
40 HANDLE handle
= INVALID_HANDLE_VALUE
;
41 DWORD cfm_flags
= 0, mvf_flags
= 0;
44 case PROT_READ
| PROT_WRITE
:
45 cfm_flags
= PAGE_READWRITE
;
46 mvf_flags
= FILE_MAP_ALL_ACCESS
;
49 cfm_flags
= PAGE_READWRITE
;
50 mvf_flags
= FILE_MAP_WRITE
;
53 cfm_flags
= PAGE_READONLY
;
54 mvf_flags
= FILE_MAP_READ
;
60 handle
= CreateFileMappingA((HANDLE
) _get_osfhandle(fd
), NULL
,
61 cfm_flags
, HIDWORD(len
), LODWORD(len
), NULL
);
65 map
= MapViewOfFile(handle
, mvf_flags
, HIDWORD(offset
),
66 LODWORD(offset
), len
);
75 int munmap(void *addr
, size_t len
)
77 if (!UnmapViewOfFile(addr
))
83 /* Reentrant string tokenizer. Generic version.
84 Copyright (C) 1991,1996-1999,2001,2004,2007 Free Software Foundation, Inc.
85 This file is part of the GNU C Library.
87 This program is free software; you can redistribute it and/or modify
88 it under the terms of the GNU General Public License as published by
89 the Free Software Foundation; either version 2, or (at your option)
92 This program is distributed in the hope that it will be useful,
93 but WITHOUT ANY WARRANTY; without even the implied warranty of
94 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
95 GNU General Public License for more details.
97 You should have received a copy of the GNU General Public License along
98 with this program; if not, write to the Free Software Foundation,
99 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
101 /* Parse S into tokens separated by characters in DELIM.
102 If S is NULL, the saved pointer in SAVE_PTR is used as
103 the next starting point. For example:
104 char s[] = "-abc-=-def";
106 x = strtok_r(s, "-", &sp); // x = "abc", sp = "=-def"
107 x = strtok_r(NULL, "-=", &sp); // x = "def", sp = NULL
108 x = strtok_r(NULL, "=", &sp); // x = NULL
111 char *strtok_r(char *s
, const char *delim
, char **save_ptr
)
118 /* Scan leading delimiters. */
119 s
+= strspn(s
, delim
);
125 /* Find the end of the token. */
127 s
= strpbrk (token
, delim
);
129 /* This token finishes the string. */
130 *save_ptr
= memchr(token
, '\0', strlen(token
));
132 /* Terminate the token and make *SAVE_PTR point past it. */