mirror of
https://git.proxmox.com/git/pve-common
synced 2025-07-27 10:01:38 +00:00
added: openat, mkdirat
This commit is contained in:
parent
150f4bc65a
commit
21c56a963f
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user