1#!/usr/bin/perl
2use test::helper qw($_real $_point);
3use Test::More;
4plan tests => 24;
5use English;
6use Unix::Mknod qw(:all);
7use Fcntl qw(S_IFCHR S_IFBLK);
8use POSIX;
9
10my (@stat);
11
12chdir($_point);
13ok(open($file, '>', 'reg'),"create normal file");
14close($file);
15ok(defined mkfifo($_point.'/fifo', 0600),"create fifo");
16
17chdir($_real);
18ok(-e "reg" ,"normal file exists");
19ok(-e "fifo","fifo exists");
20ok(-f "reg" ,"normal file is normal file");
21ok(-p "fifo","fifo is fifo");
22
23SKIP: {
24	skip('Need root to mknod devices', 8) unless ($UID == 0);
25
26	chdir($_point);
27	ok(!mknod($_point.'/chr', 0600|S_IFCHR, makedev(2,3)),"create chrdev");
28	ok(!mknod($_point.'/blk', 0600|S_IFBLK, makedev(2,3)),"create blkdev");
29
30	chdir($_real);
31	ok(-e "chr" ,"chrdev exists");
32	ok(-e "blk" ,"blkdev exists");
33
34        skip('mknod() is just pretend under fakeroot(1)', 4)
35          if exists $ENV{FAKEROOTKEY};
36
37	ok(-c "chr" ,"chrdev is chrdev");
38	ok(-b "blk" ,"blkdev is blkdev");
39
40	@stat = stat("chr");
41	is($stat[6],makedev(2,3),"chrdev has right major,minor");
42	@stat = stat("blk");
43	is($stat[6],makedev(2,3),"blkdev has right major,minor");
44}
45
46chdir($_point);
47ok(-e "reg" ,"normal file exists");
48ok(-e "fifo","fifo exists");
49ok(-f "reg" ,"normal file is normal file");
50ok(-p "fifo","fifo is fifo");
51
52SKIP: {
53	skip('Need root to mknod devices', 6) unless ($UID == 0);
54
55	ok(-e "chr" ,"chrdev exists");
56	ok(-e "blk" ,"blkdev exists");
57	ok(-c "chr" ,"chrdev is chrdev");
58	ok(-b "blk" ,"blkdev is blkdev");
59
60	@stat = stat("chr");
61	is($stat[6],makedev(2,3),"chrdev has right major,minor");
62	@stat = stat("blk");
63	is($stat[6],makedev(2,3),"blkdev has right major,minor");
64}
65
66map { unlink } qw(reg chr blk fifo);
67