Itimer.xs

filter: Statementstmt 62.5% 25 / 40 Branchbran 38.8% 7 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 55.1% 32 / 58 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« blib/lib/BSD/Itimer.pm ↑ Summary
1 /*
2 # File: Itimer.xs
3 # Author: Daniel Hagerty, hag@linnaean.org
4 # Date: Sun Jul 4 17:01:08 1999
5 # Description: XS interface to BSD derived {g,s}etitimer() functions.
6 #
7 # Copyright (c) 1999 Daniel Hagerty. All rights reserved. This program
8 # is free software; you can redistribute it and/or modify it under the
9 # same terms as Perl itself.
10 #
11 # $Id: Itimer.xs,v 1.2 1999/07/28 02:26:50 hag Exp $
12 */
13  
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 #include "EXTERN.h"
18 #include "perl.h"
19 #include "XSUB.h"
20 #ifdef __cplusplus
21 }
22 #endif
23  
24 #include <sys/time.h>
25  
26 static char *rcs_id = "$Id: Itimer.xs,v 1.2 1999/07/28 02:26:50 hag Exp $";
27  
28 static int
29 0 not_here(s)
30 char *s;
31 {
32 0 croak("%s not implemented on this architecture", s);
33 return -1;
34 }
35  
36 static double
37 1 constant(name, arg)
38 char *name;
39 int arg;
40 {
41 1 errno = 0;
42 1 ▶ switch (*name) {
Branch: 1 branch
BranchTrueFalseTotal
switch (*name) { 1 0 1
43 1 case 'I':
44 1 ▶ if (strEQ(name, "ITIMER_PROF"))
Branch: 1 branch
BranchTrueFalseTotal
if (strEQ(name, "ITIMER_PROF")) 0 1 1
45 #ifdef ITIMER_PROF
46 0 return ITIMER_PROF;
47 #else
48 goto not_there;
49 #endif
50 1 ▶ if (strEQ(name, "ITIMER_REAL"))
Branch: 1 branch
BranchTrueFalseTotal
if (strEQ(name, "ITIMER_REAL")) 1 0 1
51 #ifdef ITIMER_REAL
52 1 return ITIMER_REAL;
53 #else
54 goto not_there;
55 #endif
56 0 ▶ if (strEQ(name, "ITIMER_REALPROF"))
Branch: 1 branch
BranchTrueFalseTotal
if (strEQ(name, "ITIMER_REALPROF")) 0 0 0
57 #ifdef ITIMER_REALPROF
58 return ITIMER_REALPROF;
59 #else
60 0 goto not_there;
61 #endif
62 0 ▶ if (strEQ(name, "ITIMER_VIRTUAL"))
Branch: 1 branch
BranchTrueFalseTotal
if (strEQ(name, "ITIMER_VIRTUAL")) 0 0 0
63 #ifdef ITIMER_VIRTUAL
64 0 return ITIMER_VIRTUAL;
65 #else
66 goto not_there;
67 #endif
68 0 break;
69 }
70 0 errno = EINVAL;
71 0 return 0;
72  
73 0 not_there:
74 0 errno = ENOENT;
75 0 return 0;
76 }
77  
78 MODULE = BSD::Itimer PACKAGE = BSD::Itimer
79  
80 PROTOTYPES: enable
81  
82 double
83 constant(name,arg)
84 char * name
85 int arg
86  
87  
88 MODULE = BSD::Itimer PACKAGE = BSD::Itimer PREFIX=bsd_
89  
90 void
91 bsd_getitimer(which)
92 int which
93 PREINIT:
94 struct itimerval it;
95 int err;
96 PPCODE:
97 2 err = getitimer(which, &it);
98 2 ▶ if(err < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if(err < 0) { 0 2 2
99 0 XSRETURN_EMPTY;
100 }
101 2 ▶ EXTEND(sp, 4);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(sp, 4); 0 2 2
102 2 PUSHs(sv_2mortal(newSViv(it.it_interval.tv_sec)));
103 2 PUSHs(sv_2mortal(newSViv(it.it_interval.tv_usec)));
104 2 PUSHs(sv_2mortal(newSViv(it.it_value.tv_sec)));
105 2 PUSHs(sv_2mortal(newSViv(it.it_value.tv_usec)));
106  
107 void
108 bsd_setitimer(which, ival_sec, ival_usec, val_sec, val_usec)
109 int which
110 int ival_sec
111 int ival_usec
112 int val_sec
113 int val_usec
114 PREINIT:
115 struct itimerval setiv, getiv;
116 int err;
117 PPCODE:
118 1 setiv.it_interval.tv_sec = ival_sec;
119 1 setiv.it_interval.tv_usec = ival_usec;
120 1 setiv.it_value.tv_sec = val_sec;
121 1 setiv.it_value.tv_usec = val_usec;
122 1 err = setitimer(which, &setiv, &getiv);
123 1 ▶ if(err < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if(err < 0) { 0 1 1
124 0 XSRETURN_EMPTY;
125 }
126 1 ▶ EXTEND(sp, 4);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(sp, 4); 0 1 1
127 1 PUSHs(sv_2mortal(newSViv(getiv.it_interval.tv_sec)));
128 1 PUSHs(sv_2mortal(newSViv(getiv.it_interval.tv_usec)));
129 1 PUSHs(sv_2mortal(newSViv(getiv.it_value.tv_sec)));
130 1 PUSHs(sv_2mortal(newSViv(getiv.it_value.tv_usec)));
« blib/lib/BSD/Itimer.pm ↑ Summary