File: Sync.pm

package info (click to toggle)
libfile-sync-perl 0.09-4
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny, sarge, squeeze
  • size: 52 kB
  • ctags: 5
  • sloc: perl: 90; makefile: 55
file content (93 lines) | stat: -rw-r--r-- 2,051 bytes parent folder | download | duplicates (3)
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File::Sync.pm
#
# Copyright  1997,1999 Carey Evans.  All rights reserved.  This module is
# free software; you can redistribute it and/or modify it under the same
# terms as Perl itself.

package File::Sync;

use strict;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);

require Exporter;
require DynaLoader;
require AutoLoader;

use Carp;
use Symbol qw(qualify_to_ref);

@ISA = qw(Exporter DynaLoader);
# Items to export into callers namespace by default.
@EXPORT = ();
@EXPORT_OK = qw(
	sync
	fsync
	fsync_fd
);
$VERSION = '0.09';

bootstrap File::Sync $VERSION;

# Preloaded methods go here.

# Interface from Perl filehandle to POSIX file descriptor.
sub fsync(*) {
    @_ == 1 or croak "usage: fsync FILEHANDLE";

    fsync_fd(fileno(qualify_to_ref($_[0], caller())));
}

# Make fsync a method of IO::Handle and FileHandle.
*IO::Handle::fsync = *FileHandle::fsync = \&fsync;

1;
__END__

=head1 NAME

File::Sync - Perl access to fsync() and sync() function calls

=head1 SYNOPSIS

  use File::Sync qw(fsync sync);
  fsync(\*FILEHANDLE) or die "fsync: $!";
  sync();

  use File::Sync qw(fsync);
  use IO::File;
  $fh = IO::File->new("> /tmp/foo") 
      or die "new IO::File: $!";
  ...
  fsync($fh) or die "fsync: $!";

=head1 DESCRIPTION

The fsync() function takes a Perl file handle as its only argument, and
passes its fileno() to the C function fsync().  It returns I<undef> on
failure, or I<true> on success.

The fsync_fd() function is used internally by fsync(); it takes a file
descriptor as its only argument.

The sync() function is identical to the C function sync().

This module does B<not> export any methods by default, but fsync() is
made available as a method of the I<FileHandle> and I<IO::Handle>
classes.

=head1 NOTES

Doing fsync() if the stdio buffers aren't flushed (with C<$|> or the
I<autoflush> method) is probably pointless.

Calling sync() too often on a multi-user system is slightly antisocial.

=head1 AUTHOR

Carey Evans <I<c.evans@clear.net.nz>>

=head1 SEE ALSO

perl(1), fsync(2), sync(2), perlvar(1)

=cut