summaryrefslogtreecommitdiff
path: root/fml/lib/IO/t/file_map.pl
blob: 25b16e37bbfdc39a17a92ae59ad2d2d119eb7114 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#-*- perl -*-
#
#  Copyright (C) 2001 Ken'ichi Fukamachi
#   All rights reserved. This program is free software; you can
#   redistribute it and/or modify it under the same terms as Perl itself.
#
# $FML: file_map.pl,v 1.5 2001/08/19 16:12:25 fukachan Exp $
#

use Carp;

$file = "/etc/passwd";
$map  = "file:". $file;

open($file, $file) || croak($!);
while (1) {
    $p = sysread($file, $_, 4096);
    last unless $p;
    $orgbuf .= $_;
}
close($file);

use IO::Adapter;
$obj = new IO::Adapter $map;
$obj->open || croak("cannot open $map");
if ($obj->error) { croak( $obj->error );}
while ($x = $obj->getline) { $buf .= $x; }
$obj->close;

if ($orgbuf eq $buf) {
    print STDERR "$map reading ... ok\n";
}
else {
    exit 1;
}

exit 0;