Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ar: simplify strmode() #676

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 8 additions & 23 deletions bin/ar
Original file line number Diff line number Diff line change
Expand Up @@ -387,29 +387,14 @@ sub writeAr {
sub strmode {
my ($mode) = @_;

# just the RWX bits.
$mode = oct($mode) & 0777;
my @modemap = (0400 => 'r', # R for owner
0200 => 'w', # W for owner
0100 => 'x', # X for owner

0040 => 'r', # R for group
0020 => 'w', # W for group
0010 => 'x', # X for group

0004 => 'r', # R for other
0002 => 'w', # W for other
0001 => 'x'); # X for other

my $modestr;
while (@modemap) {
my ($bit,$letter) = splice(@modemap,0,2);
if ($mode & $bit) {
$modestr .= $letter;
}
else {
$modestr .= "-";
}
die "bad file mode: $mode" if $mode !~ m/([0-7]+)/;
my $ugo = substr $1, -3; # only rwx bits
my $modestr = '';
foreach (split //, $ugo) {
my $i = oct;
$modestr .= $i & 4 ? 'r' : '-';
$modestr .= $i & 2 ? 'w' : '-';
$modestr .= $i & 1 ? 'x' : '-';
}
return $modestr;
}
Expand Down
Loading