]>
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 * SPDX-License-Identifier: LGPL-2.0+
12 #include "mingw_support.h"
25 void *mmap(void *addr
, size_t len
, int prot
, int flags
, int fd
, int offset
)
28 HANDLE handle
= INVALID_HANDLE_VALUE
;
29 DWORD cfm_flags
= 0, mvf_flags
= 0;
32 case PROT_READ
| PROT_WRITE
:
33 cfm_flags
= PAGE_READWRITE
;
34 mvf_flags
= FILE_MAP_ALL_ACCESS
;
37 cfm_flags
= PAGE_READWRITE
;
38 mvf_flags
= FILE_MAP_WRITE
;
41 cfm_flags
= PAGE_READONLY
;
42 mvf_flags
= FILE_MAP_READ
;
48 handle
= CreateFileMappingA((HANDLE
) _get_osfhandle(fd
), NULL
,
49 cfm_flags
, HIDWORD(len
), LODWORD(len
), NULL
);
53 map
= MapViewOfFile(handle
, mvf_flags
, HIDWORD(offset
),
54 LODWORD(offset
), len
);
63 int munmap(void *addr
, size_t len
)
65 if (!UnmapViewOfFile(addr
))
71 /* Reentrant string tokenizer. Generic version.
72 Copyright (C) 1991,1996-1999,2001,2004,2007 Free Software Foundation, Inc.
73 This file is part of the GNU C Library.
75 * SPDX-License-Identifier: GPL-2.0+
78 /* Parse S into tokens separated by characters in DELIM.
79 If S is NULL, the saved pointer in SAVE_PTR is used as
80 the next starting point. For example:
81 char s[] = "-abc-=-def";
83 x = strtok_r(s, "-", &sp); // x = "abc", sp = "=-def"
84 x = strtok_r(NULL, "-=", &sp); // x = "def", sp = NULL
85 x = strtok_r(NULL, "=", &sp); // x = NULL
88 char *strtok_r(char *s
, const char *delim
, char **save_ptr
)
95 /* Scan leading delimiters. */
96 s
+= strspn(s
, delim
);
102 /* Find the end of the token. */
104 s
= strpbrk (token
, delim
);
106 /* This token finishes the string. */
107 *save_ptr
= memchr(token
, '\0', strlen(token
));
109 /* Terminate the token and make *SAVE_PTR point past it. */