blib/lib/Sys/Mknod.pm

filter: Statementstmt 50.0% 13 / 26 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 71.4% 5 / 7 Podpod n/a totaltotal 40.0% 18 / 45 CC 7 SCAR 34.2
CC
7
Cov
34%
mknod
56.0
mkfifo
2.0
BEGIN
1.0
CRAP 30.7
↑ Summary
1 =head1 NAME
2  
3 Sys::Mknod - make special files
4  
5 =head1 SYNOPSIS
6  
7 use Sys::Mknod;
8  
9 mknod ("/dev/filename", type, $major, $minor, $mode);
10 mkfifo ("filename", $mode);
11  
12 =head1 DESCRIPTION
13  
14 mknod - creates special files. Why use system() when you can use
15 syscall()?
16  
17 $mode is the resultant file mode, and defaults to 0666. It does not
18 override your umask.
19  
20 =head1 SPECIAL FILE TYPES
21  
22 $type must be one of:
23  
24 =over 4
25  
26 =item m/^c/i
27  
28 Creates a "Character Special" device.
29  
30 =item m/^b/i
31  
32 Creates a "Block Special" device"
33  
34 =back
35  
36 =cut
37  
38 package Sys::Mknod;
39  
40 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
42 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
43  
44 require Exporter;
45 our @ISA = qw(Exporter);
46  
47 # OK, so the overhead of interpreting these files pretty much
48 # obliviates the beneifit of avoiding a system(). See if I care.
49 {
50 local $^W = 0;
51 require "sys/sysmacros.ph";
52 require "sys/types.ph";
53 require "sys/syscall.ph";
54 }
55 1 ▶use Fcntl qw(S_IFCHR S_IFIFO S_IFBLK);
Subroutine BEGIN: called CC=1 SCAR=0.0
56  
57 # I'm exporting all these functions for DWIM's sake.
58 our @EXPORT = qw(mknod mkfifo);
59  
60 our $VERSION = '0.02';
61  
62 # Preloaded methods go here.
63  
64 0 ▶sub mknod($$$$;$) {
Subroutine mknod: not called CC=7 SCAR=40.3
65 0 my ($filename, $type, $major, $minor, $mode) = (@_);
66  
67 0 ▶ $mode = 0666 unless defined $mode;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $mode 0 0 0
68  
69 0 ▶ if ($type =~ m/^b/i) {
Branch: 3 branches
BranchTrueFalseTotal
if ($type =~ /^b/i) { } 0 0 0
elsif ($type =~ /^c/i) { } 0 0 0
elsif ($type =~ /^f/i) { } 0 0 0
70 0 $mode |= S_IFBLK;
71 } elsif ($type =~ m/^c/i) {
72 0 $mode |= S_IFCHR;
73 } elsif ($type =~ m/^f/i) {
74 0 $mode |= S_IFIFO;
75 } else {
76 0 croak ("Invalid special file type `$type'");
77 }
78  
79 0 ▶ my $return = syscall( &SYS_mknod, $filename, $mode,
Branch: 1 branch
BranchTrueFalseTotal
defined $major ? : 0 0 0
80 ( defined $major
81 ? makedev($major, $minor)
82 : 0 ) );
83 0 ▶ if ($return < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($return < 0) { } 0 0 0
84 0 die $!;
85 } else {
86 0 return 1;
87 }
88 }
89  
90 0 ▶sub mkfifo($;$) {
Subroutine mkfifo: not called CC=1 SCAR=6.9
91 0 my ($filename, $mode) = (@_);
92  
93 0 mknod($filename, "fifo", undef, undef, $mode);
94  
95 }
96  
97 1 ▶sub make_dev($$) {
Subroutine make_dev: called CC=1 SCAR=0.0
98 1 my ($major, $minor) = (@_);
99 1 return makedev($major, $minor);
100 }
101  
102 1;
103 __END__
↑ Summary