-
Notifications
You must be signed in to change notification settings - Fork 94
Expand file tree
/
Copy pathstat.sh
More file actions
36 lines (27 loc) · 745 Bytes
/
stat.sh
File metadata and controls
36 lines (27 loc) · 745 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/bash
source ctypes.sh
# exit on error
set -e
# Define the format of struct stat for bash
struct -m statbuf stat passwd
# stat is not exported on Linux, use xstat instead.
if test "$(uname)" == "Linux"; then
dlcall -r int __xstat 0 "/etc/passwd" $statbuf
else
dlcall -r int stat "/etc/passwd" $statbuf
fi
# Convert result into bash structure
unpack $statbuf passwd
printf "/etc/passwd\n"
printf "\tuid: %u\n" ${passwd[st_uid]##*:}
printf "\tgid: %u\n" ${passwd[st_gid]##*:}
printf "\tmode: %o\n" ${passwd[st_mode]##*:}
printf "\tsize: %u\n" ${passwd[st_size]##*:}
dlcall free $statbuf
# Check result is correct
if test ${passwd[st_size]##*:} -eq $(wc -c < /etc/passwd); then
echo PASS
exit 0
fi
echo FAIL
exit 1