MModeLattice
Workflows

Coding workflows · POSIX permission display

03
Built around your work

A concrete starting point

Format POSIX permission bits as nine readable characters. Check setuid, setgid and sticky bits with and without execute permission, rejecting negative or oversized modes without changing any file.

01

Open the context

Choose the project folder and name the files or behavior involved.

02

Define the change

Describe the input, expected output and boundaries that must stay intact.

03

Inspect the work

Review the proposed edits and any commands before relying on their result.

04

Check the outcome

Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.

POSIX permission display

A concrete starting point
def permission_text(mode):
    if type(mode) is not int or not 0 <= mode <= 0o7777:
        raise ValueError("permission bits only")
    out = []
    for shift in (6, 3, 0):
        bits = (mode >> shift) & 7
        out.extend(c if bits & bit else "-"
                   for c, bit in zip("rwx", (4, 2, 1)))
    for pos, bit, mark in ((2, 0o4000, "s"), (5, 0o2000, "s"), (8, 0o1000, "t")):
        if mode & bit: out[pos] = mark if out[pos] == "x" else mark.upper()
    return "".join(out)

The example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.

AI coding workspace

Your next change starts here.

Get the Windows app ↗