3 * *Unix·Ï¤Î¥·¥¹¥Æ¥à¥³¡¼¥ë¤ò¥½¡¼¥¹Ãæ¤Ë»¶¤é¤µ¤Ê¤¤¤¿¤á
4 * *¾ÍèŪ¤Ë¤Ï°ì¤Ä¤Î¥Õ¥¡¥¤¥ë¤òÊ£¿ô¤ÎÌÜŪ¤Ëmap¤¹¤ë¤³¤È¤â¹Íθ
6 * Copyright (C) 2005 TABATA Yusuke
10 This library is free software; you can redistribute it and/or
11 modify it under the terms of the GNU Lesser General Public
12 License as published by the Free Software Foundation; either
13 version 2 of the License, or (at your option) any later version.
15 This library is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
20 You should have received a copy of the GNU Lesser General Public
21 License along with this library; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include <sys/types.h>
31 #include <anthy/filemap.h>
32 #include <anthy/logger.h>
37 /* mmap¤·¤¿¥¢¥É¥ì¥¹ */
39 /* mmap¤·¤¿Îΰè¤ÎŤµ */
44 anthy_mmap(const char *fn, int wr)
49 struct filemapping *m;
56 prot = PROT_READ | PROT_WRITE;
58 mode = S_IRUSR | S_IWUSR;
65 fd = open(fn, flags, mode);
68 anthy_log(0, "Failed to open (%s).\n", fn);
74 anthy_log(0, "Failed to stat() (%s).\n", fn);
78 if (st.st_size == 0) {
79 anthy_log(0, "Failed to mmap 0size file (%s).\n", fn);
84 ptr = mmap(NULL, st.st_size, prot, MAP_SHARED, fd, 0);
86 if (ptr == MAP_FAILED) {
87 anthy_log(0, "Failed to mmap() (%s).\n", fn);
91 /* mmap¤ËÀ®¸ù¤·¤¿¤Î¤Ç¾ðÊó¤òÊÖ¤¹ */
92 m = malloc(sizeof(struct filemapping));
101 anthy_mmap_address(struct filemapping *m)
110 anthy_mmap_size(struct filemapping *m)
119 anthy_mmap_is_writable(struct filemapping *m)
128 anthy_munmap(struct filemapping *m)
133 munmap(m->ptr, m->size);