summaryrefslogtreecommitdiffstats
path: root/tests/018/chmod.tl
blob: 16b96ad03de48b27a4f503ec63bcdc0bac8922ef (plain)
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
37
38
39
40
41
(load "../common")
(load "../perm")

(defvarl tgt [*args* 0])

(defmacro mode-bits (st-mode)
  (logand st-mode #xFFF))

(defun cht (init mode expected)
  (let ((ini (dec-perm init))
        (exp (dec-perm expected)))
    (chmod tgt ini)
    (let* ((st (stat tgt))
           (m (logand st.mode #xFFF)))
      (unless (eql m ini)
        (error "failed to set initial mode: expected: ~s, actual: ~s "
               init (enc-perm m))))
    (chmod tgt mode)
    (let* ((st (stat tgt))
           (m (logand st.mode #xFFF)))
      (unless (eql m exp)
        (error "failed to set mode: expected ~s, actual ~s"
               expected (enc-perm m))))))

(remove-path tgt)
(with-stream (s (open-file tgt "w")))
(umask #o022)

(cht "------------" "a+strwx"           "sgtrwxrwxrwx")
(cht "------------" "+strwx"            "sgtrwxr-xr-x")
(cht "------------" "u+s"               "s-----------")
(cht "------------" "g+s"               "-g----------")
(cht "------------" "+t"                "--t---------")
(cht "sgtrwxrwxrwx" "="                 "------------")
(cht "sgtrwxrwxrwx" "u="                "--t---rwxrwx")
(cht "sgtrwxrwxrwx" "g="                "--trwx---rwx")
(cht "sgtrwxrwxrwx" "o="                "---rwxrwx---")
(cht "------------" "u+s,g+s"           "sg----------")
(cht "------------" "u+r,g+r,o+r,+t,+s" "sgtr--r--r--")
(cht "------------" "+rwx,g-r+w,o-r+w"  "---rwx-wx-wx")
(cht "---------rwx" "u=rwsx"            "s--rwx---rwx")