memmap_unix.c

filter: Statementstmt 72.7% 16 / 22 Branchbran 50.0% 9 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 62.5% 25 / 40 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« jis.c ↑ Summary getcode.c »
1  
2 /* $Id: memmap_unix.c 4599 2005-08-05 05:22:08Z hio $ */
3  
4 #include "Japanese.h"
5 #include <unistd.h> /* memmap */
6 #include <sys/mman.h> /* memmap */
7 #include <sys/stat.h> /* stat */
8 #include <fcntl.h> /* 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 21 do_memmap(void)
26 {
27 int fd_pmfile;
28 struct stat st_pmfile;
29
30 {
31 /* (ja)½é´ü²½¤ò³Îǧ */
32 /* ensure initialize. */
33 21 SV* sv = get_sv("Unicode::Japanese::PurePerl::HEADLEN",0);
34 21 ▶ if( sv==NULL || !SvOK(sv) )
Branch: 2 branches
BranchTrueFalseTotal
if( sv==NULL || !SvOK(sv) ) 21 0 21
if( sv==NULL || !SvOK(sv) ) 0 21 21
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 21 sv_fd = eval_pv("fileno($Unicode::Japanese::PurePerl::FH)",G_KEEPERR|G_SCALAR|G_NOARGS);
45 21 ▶ if( sv_fd==NULL || !SvOK(sv_fd) || !SvIOK(sv_fd) )
Branch: 3 branches
BranchTrueFalseTotal
if( sv_fd==NULL || !SvOK(sv_fd) || !SvIOK(sv_fd) ) 21 0 21
if( sv_fd==NULL || !SvOK(sv_fd) || !SvIOK(sv_fd) ) 21 0 21
if( sv_fd==NULL || !SvOK(sv_fd) || !SvIOK(sv_fd) ) 0 21 21
46 {
47 0 croak("Unicode::Japanese#do_memmap, could not get fd of FH");
48 }
49 21 fd_pmfile = SvIV(sv_fd);
50 21 ▶ if( fstat(fd_pmfile,&st_pmfile)!=0 )
Branch: 1 branch
BranchTrueFalseTotal
if( fstat(fd_pmfile,&st_pmfile)!=0 ) 0 21 21
51 {
52 0 croak("Unicode::Japanese#do_memmap, stat failed: fd [%d]: %s",fd_pmfile,strerror(errno));
53 }
54 }
55
56 {
57 /* mmap */
58 21 s_mmap_pmfile_size = st_pmfile.st_size;
59 21 s_mmap_pmfile = (char*)mmap(NULL,s_mmap_pmfile_size,PROT_READ,MAP_PRIVATE,fd_pmfile,0);
60 21 ▶ if( s_mmap_pmfile==MAP_FAILED )
Branch: 1 branch
BranchTrueFalseTotal
if( s_mmap_pmfile==MAP_FAILED ) 0 21 21
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 21 do_memmap_set(s_mmap_pmfile,s_mmap_pmfile_size);
69
70 21 return;
71 }
72  
73 /* ----------------------------------------------------------------------------
74 * ¥á¥â¥ê¥Þ¥Ã¥×¤Î²ò½ü
75 */
76 void
77 21 do_memunmap(void)
78 {
79 /* printf("* do_memunmap() *\n"); */
80  
81 21 ▶ if( s_mmap_pmfile!=NULL )
Branch: 1 branch
BranchTrueFalseTotal
if( s_mmap_pmfile!=NULL ) 21 0 21
82 {
83 21 ▶ if( munmap(s_mmap_pmfile,s_mmap_pmfile_size)==-1 )
Branch: 1 branch
BranchTrueFalseTotal
if( munmap(s_mmap_pmfile,s_mmap_pmfile_size)==-1 ) 0 21 21
84 {
85 0 Perl_warn(aTHX_ "Unicode::Japanese#do_memunmap, munmap failed: %s",strerror(errno));
86 }
87 }
88
89 21 return;
90 }
91  
92 /* ----------------------------------------------------------------------------
93 * End of File.
94 * ------------------------------------------------------------------------- */
« jis.c ↑ Summary getcode.c »