Skip to content

Commit 6065ad9

Browse files
authored
ar: simplify strmode() (#889)
* When running "ar -tv file.a", the file permissions of archive members are listed * Use the file mode number directly instead of splitting the input octal string and converting each part to a separate number * I tested that I still get the same mode string for an archive compared to binutils ar
1 parent a0beaf3 commit 6065ad9

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

bin/ar

+2-3
Original file line numberDiff line numberDiff line change
@@ -390,10 +390,9 @@ sub strmode {
390390
my ($mode) = @_;
391391

392392
die "bad file mode: $mode" if $mode !~ m/([0-7]+)/;
393-
my $ugo = substr $1, -3; # only rwx bits
393+
my $m = oct $mode;
394394
my $modestr = '';
395-
foreach ( split //, $ugo ) {
396-
my $i = oct;
395+
foreach my $i ($m >> 6, $m >> 3, $m) {
397396
$modestr .= $i & 4 ? 'r' : '-';
398397
$modestr .= $i & 2 ? 'w' : '-';
399398
$modestr .= $i & 1 ? 'x' : '-';

0 commit comments

Comments
 (0)