File: 04_fdatasync.t

package info (click to toggle)
libfile-sync-perl 0.11-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 92 kB
  • sloc: perl: 118; makefile: 2
file content (43 lines) | stat: -rwxr-xr-x 1,133 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
#! ./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";