]> Sergey Matveev's repositories - public-inbox.git/commitdiff
syscall: golf + more idiomatic buffer initialization
authorEric Wong <e@80x24.org>
Mon, 18 Apr 2022 09:50:04 +0000 (09:50 +0000)
committerEric Wong <e@80x24.org>
Mon, 18 Apr 2022 21:53:47 +0000 (21:53 +0000)
While `vec' is useful for user-supplied buffers to avoid excess
memory traffic, but provides no benefit when we need to allocate
our own buffers as we do in nodatacow_fh, since Perl can't elide
memset(ptr, 0, len).  So just use the idiomatic `"\0" x $LEN' here.

lib/PublicInbox/Syscall.pm

index cc282f9ff6bb3a3079913f1a8ecb1005fc61d0be..22b779ad6933464e327340593669439e12b3aef6 100644 (file)
@@ -390,12 +390,10 @@ sub rename_noreplace ($$) {
        }
 }
 
-sub nodatacow_fh {
-       return if !defined($SYS_fstatfs);
-       my $buf = '';
-       vec($buf, 120 * 8 - 1, 1) = 0;
+sub nodatacow_fh ($) {
        my ($fh) = @_;
-       syscall($SYS_fstatfs, fileno($fh), $buf) == 0 or
+       my $buf = "\0" x 120;
+       syscall($SYS_fstatfs // return, fileno($fh), $buf) == 0 or
                return warn("fstatfs: $!\n");
        my $f_type = unpack('l!', $buf); # statfs.f_type is a signed word
        return if $f_type != 0x9123683E; # BTRFS_SUPER_MAGIC