File-Sync-0.11/0000755000175000017500000000000011662004777011374 5ustar skiskiFile-Sync-0.11/MANIFEST0000644000175000017500000000027211662004777012526 0ustar skiskiChanges MANIFEST Makefile.PL README Sync.pm Sync.xs t/01_fsync.t t/02_error.t t/03_sync.t t/04_fdatasync.t META.yml Module meta-data (added by MakeMaker) File-Sync-0.11/t/0000755000175000017500000000000011662004777011637 5ustar skiskiFile-Sync-0.11/t/01_fsync.t0000755000175000017500000000170511661623440013445 0ustar skiski#! ./perl ######################### We start with some black magic to print on failure. BEGIN { $| = 1; print "1..5\n"; } END {print "not ok 1\n" unless $loaded;} use File::Sync qw(fsync); use FileHandle; $loaded = 1; print "ok 1\n"; ######################### End of black magic. # Open a file for testing, unlink it in case we crash. open TEST, "> /tmp/test.pl.$$" or die "couldn't create temp. file - please try again"; unlink "/tmp/test.pl.$$"; # Try fsync, with glob ref then glob name. fsync(\*TEST) || print 'not '; print "ok 2\n"; fsync(TEST) || print 'not '; print "ok 3\n"; # Try fsync_fd on fd of TEST. $fd = fileno(TEST); File::Sync::fsync_fd($fd) || print 'not '; print "ok 4\n"; close TEST; # Open file as FileHandle and unlink it. $fh = new FileHandle "> /tmp/test.pl.$$" or die "couldn't create temp. file - please try again"; unlink "/tmp/test.pl.$$"; # Try fsync as method of FileHandle. $fh->fsync() || print 'not '; print "ok 5\n"; File-Sync-0.11/t/02_error.t0000755000175000017500000000312011661623440013446 0ustar skiski#! ./perl ######################### We start with some black magic to print on failure. BEGIN { $| = 1; print "1..8\n"; } END {print "not ok 1\n" unless $loaded;} use File::Sync qw(fsync); use FileHandle; use POSIX qw(:errno_h); $loaded = 1; print "ok 1\n"; ######################### End of black magic. # Check errors for wrong number of arguments. eval "fsync(\*STDOUT, 1)"; unless ($@ and $@ =~ m/^Too many arguments/) { print STDERR $@; print 'not '; } print "ok 2\n"; eval "File::Sync::fsync_fd()"; unless ($@ and $@ =~ m/^Not enough arguments/) { print STDERR $@; print 'not '; } print "ok 3\n"; eval { &fsync(); }; unless ($@ and $@ =~ m/^usage:/i) { print STDERR $@; print 'not '; } print "ok 4\n"; eval { &File::Sync::fsync_fd(0, 0); }; unless ($@ and $@ =~ m/^usage:/i) { print STDERR $@; print 'not '; } print "ok 5\n"; # Open a file for testing, unlink it in case we crash. $fh = new FileHandle "> /tmp/test.pl.$$" or die "couldn't create temp. file - please try again"; unlink "/tmp/test.pl.$$"; # Check number of arguments on method invocation. eval { $fh->fsync(1); }; unless ($@ and $@ =~ m/^usage/) { print STDERR $@; print 'not '; } print "ok 6\n"; # Close it so we have a known closed file descriptor. $fd = fileno($fh); close $fh; # Try fsync_fd on closed file, make sure error is EBADF. $! = 0; File::Sync::fsync_fd($fd) && print 'not '; print "ok 7\n"; ($! == EBADF) || print 'not '; print "ok 8\n"; # Try fsync on a tty, make sure it fails. # >>> Oops! Turns out this is a test for Linux. #open TTY, '> /dev/tty' || die; #fsync(\*TTY) && print 'not '; print "ok 9\n"; File-Sync-0.11/t/04_fdatasync.t0000755000175000017500000000215511661623440014302 0ustar skiski#! ./perl ######################### We start with some black magic to print on failure. BEGIN { $| = 1; if(-e ".no_fdatasync") { warn "fdatasync() not detected, skipping tests...\n"; print "1..1\nok 1\n"; exit; } print "1..4\n"; } END {print "not ok 1\n" unless $loaded;} use File::Sync qw(fdatasync); use FileHandle; $loaded = 1; print "ok 1\n"; ######################### End of black magic. # Open a file for testing, unlink it in case we crash. open TEST, "> /tmp/test.pl.$$" or die "couldn't create temp. file - please try again"; unlink "/tmp/test.pl.$$"; # Try fdatasync, with glob ref then glob name. fdatasync(\*TEST) || print 'not '; print "ok 2\n"; fdatasync(TEST) || print 'not '; print "ok 3\n"; # Try fdatasync_fd on fd of TEST. $fd = fileno(TEST); File::Sync::fdatasync_fd($fd) || print 'not '; print "ok 4\n"; close TEST; ## Open file as FileHandle and unlink it. #$fh = new FileHandle "> /tmp/test.pl.$$" # or die "couldn't create temp. file - please try again"; #unlink "/tmp/test.pl.$$"; # ## Try fdatasync as method of FileHandle. #$fh->fdatasync() || print 'not '; print "ok 5\n"; File-Sync-0.11/t/03_sync.t0000755000175000017500000000111611661623440013275 0ustar skiski#! ./perl ######################### We start with some black magic to print on failure. BEGIN { $| = 1; print "1..4\n"; } END {print "not ok 1\n" unless $loaded;} use File::Sync qw(sync); $loaded = 1; print "ok 1\n"; ######################### End of black magic. # Make sure sync doesn't crash. sync(); print "ok 2\n"; # Test error-checking: number of arguments. eval "sync(1)"; unless ($@ and $@ =~ m/^Too many arguments/) { print STDERR $@; print 'not '; } print "ok 3\n"; eval { &sync(1); }; unless ($@ and $@ =~ m/^usage:/i) { print STDERR $@; print 'not '; } print "ok 4\n"; File-Sync-0.11/Sync.xs0000644000175000017500000000156711661623440012666 0ustar skiski/* File::Sync.xs * * Copyright © 1996,1997 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. */ #ifdef __cplusplus extern "C" { #endif #include "EXTERN.h" #include "perl.h" #include "XSUB.h" #ifdef __cplusplus } #endif #include #ifndef HAVE_SYNC int sync() { return 0; } #endif #ifndef HAVE_FDATASYNC int fdatasync(int fh) { croak("skipping unsupported fdatasync() call - you might want to use fsync() instead"); return 0; } #endif MODULE = File::Sync PACKAGE = File::Sync PROTOTYPES: ENABLE void sync() PROTOTYPE: SV* fsync_fd(fd) int fd PROTOTYPE: $ CODE: if (fsync(fd) == -1) XSRETURN_UNDEF; else XSRETURN_YES; SV* fdatasync_fd(fd) int fd PROTOTYPE: $ CODE: if (fdatasync(fd) == -1) XSRETURN_UNDEF; else XSRETURN_YES; File-Sync-0.11/Changes0000644000175000017500000000323711662004761012665 0ustar skiskiRevision history for Perl extension File::Sync. 0.11 Sat, Nov 19 2011 14:56:15 -0500 - stop clobbering IO::Handle::fsync, fix: https://rt.cpan.org/Public/Bug/Display.html?id=50418 0.10 Sat, Nov 19 2011 12:44:01 -0500 - Support for fdatasync() 0.09 Sun, 28 Nov 1999 15:43:38 +1300 - Fixed my code so that bare glob refs _do_ work with Perl 5.005. 0.08 Sat, 20 Nov 1999 18:26:20 +1300 - Updated synopsis to remove bare glob ref from example, that doesn't work any more with Perl 5.005. 0.07 Mon, 19 Jul 1999 22:01:06 +1200 - Perl 5.005 `make test' fails on fsync(TEST), so this test has been removed from t/01_fsync.t. 0.06 Sun, 10 Aug 1997 16:18:16 +1200 - OS/2 doesn't have a sync() function. Make it a no-op if ExtUtils::MakeMaker thinks the machine is OS/2. Thanks to Eric Veldhuyzen for letting me know about this. 0.05 Fri, 18 Apr 1997 12:08:00 +1200 - OK, only Linux returns an error when fsync'ing a TTY. Time to release a version without the test. Tue, 1 Apr 1997 22:53:56 +1200 - Irix doesn't return error when fsync'ing a TTY. Removed test. 0.04 Sun, 16 Feb 1997 17:04:10 +1300 - Functions are *NOT* exported by default any more. Updated documentation and tests accordingly. 0.03 Fri Jan 24 21:55:00 1997 - Revamped test scripts and documentation. - Added usage check (number of args) to fsync(). - Aliases in FileHandle and IO::Handle for fsync method. 0.02 Mon Dec 16 23:30:00 1996 - Sync.xs now uses XSRETURN_UNDEF, XSRETURN_YES. - test.pl checks for correct behaviour on errors. - Added README ready for distribution. 0.01 Mon Nov 25 20:19:12 1996 - original version; created by h2xs 1.16 File-Sync-0.11/README0000644000175000017500000000275511661623440012256 0ustar skiskiThis is version 0.07 of the Perl 5 File::Sync module. It provides Perl interfaces to the Unix sync(2) and POSIX.1b fsync(2) system calls. The fsync() call is needed for putting messages into qmail maildirs, and sync() is included for completeness. You will need at least Perl 5.003 to use this module. 5.002 might work but has not been tested. You will also need a C compiler for the XS part of the module. >>> For verson 0.09, the fsync() code has been fixed to work properly >>> with glob names as file handles in Perl 5.005. ---------- To install the module, enter these commands: perl Makefile.PL make make test make install ---------- Please send any bugs and/or ideas to Carey Evans at . Is there anything that can be done to make this module work like the POSIX fsync() call on non-POSIX machines, for example? Is there any way to test whether the fsync() call has actually happened in the tests? Thanks to everyone who reported the bug in t/02_error.t. Thanks to Eric Veldhuyzen for letting me know about sync() not existing in OS/2. Thanks to David Muir Sharnoff for getting me to actually work out what was going on and fix my code. All files contained in this installation are copyright © 1996,1997,1999 Carey Evans except for parts from the Perl distribution. All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. -- Carey Evans, , 28 November 1999. File-Sync-0.11/META.yml0000644000175000017500000000072311662004777012647 0ustar skiski--- #YAML:1.0 name: File-Sync version: 0.11 abstract: ~ author: [] license: unknown distribution_type: module configure_requires: ExtUtils::MakeMaker: 0 build_requires: ExtUtils::MakeMaker: 0 requires: {} no_index: directory: - t - inc generated_by: ExtUtils::MakeMaker version 6.56 meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 File-Sync-0.11/Sync.pm0000644000175000017500000000520711662003770012642 0ustar skiski# 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 fdatasync fsync fdatasync_fd fsync_fd ); $VERSION = '0.11'; 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()))); } sub fdatasync(*) { @_ == 1 or croak "usage: fdatasync FILEHANDLE"; fdatasync_fd(fileno(qualify_to_ref($_[0], caller()))); } ## Make fsync available as a method of FileHandle *FileHandle::fsync = \&fsync; # note: we no longer clobber IO::Handle::fsync. see POD for more. 1; __END__ =head1 NAME File::Sync - Perl access to fsync() and sync() function calls =head1 SYNOPSIS use File::Sync qw(fsync sync); sync(); fsync(\*FILEHANDLE) or die "fsync: $!"; # and if fdatasync() is available on your system: fdatasync($fh) or die "fdatasync: $!"; use File::Sync qw(fsync); use FileHandle; $fh = new FileHandle("> /tmp/foo") or die "new FileHandle: $!"; ... $fh->fsync() 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 on failure, or I on success. fdatasync() is identical in return value, but it calls C fdatasync() instead of fsync(), synchronizing only the data in the file, not the metadata. 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 export any methods by default, but fsync() is made available as a method of the I class. Note carefully that as of 0.11, we no longer clobber anything in I. You can replace any calls to IO::Handle::fsync() with IO::Handle::sync(): https://rt.cpan.org/Public/Bug/Display.html?id=50418 =head1 NOTES Doing fsync() if the stdio buffers aren't flushed (with C<$|> or the I method) is probably pointless. Calling sync() too often on a multi-user system is slightly antisocial. =head1 AUTHOR Carey Evans > =head1 SEE ALSO perl(1), fsync(2), sync(2), perlvar(1) =cut File-Sync-0.11/Makefile.PL0000644000175000017500000000544511661623440013347 0ustar skiskiuse ExtUtils::MakeMaker; use Config qw(%Config); #for $Config{cc} use Getopt::Long; use strict; my ($force_cflags, $force_cc) = ('', undef); unless( GetOptions( 'cc=s' => \$force_cc, 'cflags=s' => \$force_cflags ) ) { die "usage: $0 [ -cc=/path/to/cc ] [ -cflags='-O -fPIC' ]\n". " -cc is used to specify the path to the cc you would like to\n". " use if autodetection fails. similarly for -cflags, which is\n". " particularly useful when building with a different cc than\n". " the one which was used to build perl. -cflags also accepts\n". " the shortcut argument \"gcc\" which uses options for that\n". " compiler.\n"; } #TODO: is this general enough? if($force_cflags eq 'gcc') { $force_cflags = '-O -g -fPIC -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64'; } sub chk_sync () { # Work out -D... for Sync.o. # Apparently, OS/2 doesn't implement sync(). if (defined $ExtUtils::MakeMaker::Is_OS2 and $ExtUtils::MakeMaker::Is_OS2) { warn "OS/2 doesn't implement sync() - making it a no-op.\n"; return ''; } return '-DHAVE_SYNC'; } sub chk_fdatasync () { print "Testing if you have a working C compiler and the needed header files...\n"; open(FH, ">.no_fdatasync") || die "internal error"; close(FH) || die "internal error"; unless(open(FH, ">compile.c")) { warn "cannot write compile.c, skipping fdatasync() support\n"; return ''; } print FH <<'EOF'; #include #include #include #include int main() { fdatasync(0); return 0; } EOF unless(close(FH)) { warn "cannot close compile.c, skipping fdatasync() support\n"; return ''; } #sometimes $Config{CC} is not the answer (e.g. solaris10 w/ gcc but #no sun c package installed)... my @cc_alternatives = ( $Config{cc}, qw( cc gcc egcs icc pcc lcc )); #if all fails but CC env var is set, try it, maybe it will link push @cc_alternatives, $ENV{CC} if($ENV{CC}); unshift @cc_alternatives, $force_cc if(defined($force_cc)); my ($ret, $CC); print "trying compilers: "; foreach my $cc ( @cc_alternatives ) { print "$cc... "; my $cmd = "$cc compile.c -o compile$Config{exe_ext}"; $ret = system($cmd); if($ret==0) { $CC=$cc; last }; } foreach my $file (glob('compile*')) { unlink($file) || warn "Could not delete $file: $!\n"; } if ($ret == 0) { warn "fdatasync() support detected, including\n"; unlink ".no_fdatasync"; return '-DHAVE_FDATASYNC'; } else { warn "fdatasync() support not detected, skipping it\n"; return ''; } } WriteMakefile( 'NAME' => 'File::Sync', 'VERSION_FROM' => 'Sync.pm', # finds $VERSION 'DEFINE' => chk_sync().' '.chk_fdatasync(), 'dist' => { COMPRESS => 'gzip -9', SUFFIX => 'gz' }, );