logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git
commit: 5f710b994abe117862214072869e78f54ee950b7
parent e41e8eead360738ef399bd1cf8f7e035974e68a2
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Tue, 15 Oct 2024 12:47:52 +0200

lib/symbolize_mode: capitalize s/t when execute bit isn't set

This is inspired by NetBSD.

Diffstat:

Mlib/symbolize_mode.c20++++++++++----------
Mtest-lib/t_symbolize_mode.c6+++++-
2 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/lib/symbolize_mode.c b/lib/symbolize_mode.c @@ -42,24 +42,24 @@ symbolize_mode(mode_t mode, char str[11]) str[1] = FIELD_MATCH(mode, S_IRUSR) ? 'r' : '-'; str[2] = FIELD_MATCH(mode, S_IWUSR) ? 'w' : '-'; - if(FIELD_MATCH(mode, S_IXUSR)) - str[3] = FIELD_MATCH(mode, S_ISUID) ? 's' : 'x'; + if(FIELD_MATCH(mode, S_ISUID)) + str[3] = FIELD_MATCH(mode, S_IXUSR) ? 's' : 'S'; else - str[3] = '-'; + str[3] = FIELD_MATCH(mode, S_IXUSR) ? 'x' : '-'; str[4] = FIELD_MATCH(mode, S_IRGRP) ? 'r' : '-'; str[5] = FIELD_MATCH(mode, S_IWGRP) ? 'w' : '-'; - if(FIELD_MATCH(mode, S_IXGRP)) - str[6] = FIELD_MATCH(mode, S_ISGID) ? 's' : 'x'; + if(FIELD_MATCH(mode, S_ISGID)) + str[6] = FIELD_MATCH(mode, S_IXGRP) ? 's' : 'S'; else - str[6] = '-'; + str[6] = FIELD_MATCH(mode, S_IXGRP) ? 'x' : '-'; str[7] = FIELD_MATCH(mode, S_IROTH) ? 'r' : '-'; str[8] = FIELD_MATCH(mode, S_IWOTH) ? 'w' : '-'; - if(FIELD_MATCH(mode, S_IXOTH)) - str[9] = FIELD_MATCH(mode, S_ISVTX) ? 't' : 'x'; + if(FIELD_MATCH(mode, S_ISVTX)) + str[9] = FIELD_MATCH(mode, S_IXOTH) ? 't' : 'T'; else - str[9] = '-'; + str[9] = FIELD_MATCH(mode, S_IXOTH) ? 'x' : '-'; - str[10] = 0; + str[10] = '\0'; } diff --git a/test-lib/t_symbolize_mode.c b/test-lib/t_symbolize_mode.c @@ -31,13 +31,17 @@ t_symbolize_mode(mode_t mode, const char *expected) int main(void) { - int plan = 3; + int plan = 6; printf("1..%d\n", plan); t_symbolize_mode(0040000, "d---------"); t_symbolize_mode(0040755, "drwxr-xr-x"); t_symbolize_mode(0020644, "crw-r--r--"); + t_symbolize_mode(0024644, "crwSr--r--"); + t_symbolize_mode(0022774, "crwxrwsr--"); + t_symbolize_mode(0021744, "crwxr--r-T"); + assert(counter == plan); return err; }