File Coverage

memmap_unix.c
Criterion Covered Total %
statement 16 22 72.7
branch 9 18 50.0
condition n/a
subroutine n/a
pod n/a
total 25 40 62.5


line stmt bran cond sub pod time code
1              
2             /* $Id: memmap_unix.c 4599 2005-08-05 05:22:08Z hio $ */
3              
4             #include "Japanese.h"
5             #include /* memmap */
6             #include /* memmap */
7             #include /* stat */
8             #include /* open */
9              
10             #ifndef MAP_FAILED
11             #define MAP_FAILED ((void*)-1)
12             #endif
13              
14             /* pointer to mapped file */
15             static char* s_mmap_pmfile;
16             static int s_mmap_pmfile_size;
17              
18             /* split mapping table. */
19             extern void do_memmap_set(const char* mmap_pmfile, int mmap_pmfile_size);
20              
21             /* ----------------------------------------------------------------------------
22             * mmap data files.
23             */
24             void
25 27           do_memmap(void)
26             {
27             int fd_pmfile;
28             struct stat st_pmfile;
29            
30             {
31             /* (ja)初期化を確認 */
32             /* ensure initialize. */
33 27           SV* sv = get_sv("Unicode::Japanese::PurePerl::HEADLEN",0);
34 27 50         if( sv==NULL || !SvOK(sv) )
    50          
35             { /* not loaded yet. */
36             /* load now. */
37 0           call_pv("Unicode::Japanese::PurePerl::_init_table",G_NOARGS|G_DISCARD);
38             }
39             }
40            
41             {
42             /* get file descriptor and size. */
43             SV* sv_fd;
44 27           sv_fd = eval_pv("fileno($Unicode::Japanese::PurePerl::FH)",G_KEEPERR|G_SCALAR|G_NOARGS);
45 27 50         if( sv_fd==NULL || !SvOK(sv_fd) || !SvIOK(sv_fd) )
    50          
    50          
46             {
47 0           croak("Unicode::Japanese#do_memmap, could not get fd of FH");
48             }
49 27           fd_pmfile = SvIV(sv_fd);
50 27 50         if( fstat(fd_pmfile,&st_pmfile)!=0 )
51             {
52 0           croak("Unicode::Japanese#do_memmap, stat failed: fd [%d]: %s",fd_pmfile,strerror(errno));
53             }
54             }
55            
56             {
57             /* mmap */
58 27           s_mmap_pmfile_size = st_pmfile.st_size;
59 27           s_mmap_pmfile = (char*)mmap(NULL,s_mmap_pmfile_size,PROT_READ,MAP_PRIVATE,fd_pmfile,0);
60 27 50         if( s_mmap_pmfile==MAP_FAILED )
61             {
62 0           s_mmap_pmfile = NULL;
63 0           croak("Unicode::Japanese#do_memmap, mmap failed: %s",strerror(errno));
64             }
65             }
66            
67             /* bind each table. */
68 27           do_memmap_set(s_mmap_pmfile,s_mmap_pmfile_size);
69            
70 27           return;
71             }
72              
73             /* ----------------------------------------------------------------------------
74             * メモリマップの解除
75             */
76             void
77 27           do_memunmap(void)
78             {
79             /* printf("* do_memunmap() *\n"); */
80              
81 27 50         if( s_mmap_pmfile!=NULL )
82             {
83 27 50         if( munmap(s_mmap_pmfile,s_mmap_pmfile_size)==-1 )
84             {
85 0           Perl_warn(aTHX_ "Unicode::Japanese#do_memunmap, munmap failed: %s",strerror(errno));
86             }
87             }
88            
89 27           return;
90             }
91              
92             /* ----------------------------------------------------------------------------
93             * End of File.
94             * ------------------------------------------------------------------------- */