]> git.proxmox.com Git - pve-common.git/commitdiff
added: openat, mkdirat
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Tue, 31 May 2016 12:58:26 +0000 (14:58 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Wed, 1 Jun 2016 09:29:49 +0000 (11:29 +0200)
src/PVE/Tools.pm

index 8c7f3733f80aa0c0338a09c6d9d314122138a342..3ad37940fdbb1fcfc298957bd3f5784e3baa82aa 100644 (file)
@@ -12,6 +12,7 @@ use Filesys::Df (); # don't overwrite our df()
 use IO::Pipe;
 use IO::File;
 use IO::Dir;
+use IO::Handle;
 use IPC::Open3;
 use Fcntl qw(:DEFAULT :flock);
 use base 'Exporter';
@@ -1322,4 +1323,24 @@ sub validate_ssh_public_keys {
     }
 }
 
+sub openat($$$;$) {
+    my ($dirfd, $pathname, $flags, $mode) = @_;
+    my $fd = syscall(257, $dirfd, $pathname, $flags, $mode//0);
+    return undef if $fd < 0;
+    # sysopen() doesn't deal with numeric file descriptors apparently
+    # so we need to convert to a mode string for IO::Handle->new_from_fd
+    my $flagstr = ($flags & O_RDWR) ? 'rw' : ($flags & O_WRONLY) ? 'w' : 'r';
+    my $handle = IO::Handle->new_from_fd($fd, $flagstr);
+    return $handle if $handle;
+    my $err = $!; # save error before closing the raw fd
+    syscall(3, $fd); # close
+    $! = $err;
+    return undef;
+}
+
+sub mkdirat($$$) {
+    my ($dirfd, $name, $mode) = @_;
+    return syscall(258, $dirfd, $name, $mode) == 0;
+}
+
 1;