-
Notifications
You must be signed in to change notification settings - Fork 138
/
io.pir
49 lines (37 loc) · 978 Bytes
/
io.pir
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
38
39
40
41
42
43
44
45
46
47
48
49
# Copyright (C) 2001-2008, Parrot Foundation.
# $Id$
=head1 NAME
examples/pir/io.pir - IO Example
=head1 SYNOPSIS
% ./parrot examples/pir/io.pir
=head1 DESCRIPTION
Simple open/seek/write/close on a file. After the file is written it is read in again
and printed to STDOUT.
You should check where the file is going to be before you run this.
=cut
.sub 'example' :main
.local string test_fn
test_fn = "tmp_example_io.tmp"
$P0 = open test_fn, 'w'
seek $P0, 300, 0
# 64bit version of seek with high 32bits = 0
#seek $IO, $P0, 0, 400, 0
print $P0, "test1\n"
print $P0, "test2\n"
print $P0, "test3\n"
seek $P0, 0, 0
print $P0, "test4\n"
print $P0, "test5\n"
close $P0
$P0 = open test_fn, 'r'
$S0 = read $P0, 1024
print $S0
# now clean up after ourselves.
$P1 = new "OS"
$P1."rm"(test_fn)
.end
# Local Variables:
# mode: pir
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4 ft=pir: