modechange.c (Feature added) - Binary mode support. (original) (raw)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
From: | Raphael S Carvalho |
---|---|
Subject: | modechange.c (Feature added) - Binary mode support. |
Date: | Sat, 24 Nov 2012 00:30:18 -0200 |
Hi,
I found some questions on the internet wondering whether chmod tool does support binary numbers as input.
Even though it doesn't support I downloaded core-utils source and got started reading chmode code.
Let's to the point: I added binary input support by making changes into the /lib/modechanges.c file.
PS: (b) prefix is not case sensitive.
Tests:
./chmod b10111 t
stat t (0027/-----w-rwx)
./chmod b t (Error)
./chmod: invalid mode: `b'
./chmod b111111 t
stat t (0077/----rwxrwx)
Octal mode fulfills its goal very well, though Binary mode may be an interesting feature.
Follows the changes:
--- modechange.c~ 2012-11-24 00:03:36.000000000 -0200
+++ modechange.c 2012-11-23 23:54:45.000000000 -0200
@@ -137,6 +137,31 @@
struct mode_change *mc;
size_t used = 0;
+ if (*mode_string == 'b' || *mode_string == 'B')
+ {
+ unsigned int binary_mode = 0;
+ mode_t mode;
+ mode_t mentioned;
- + // Jumps the b character
+ mode_string++;
+ do
+ {
+ binary_mode = (binary_mode << 1) + *mode_string++ - '0';
+ if (ALLM < binary_mode)
+ return NULL;
+ }
+ while ('0' <= *mode_string && *mode_string <= '1'); - + if (*mode_string)
+ return NULL;
+
+ // Octal_to_mode function will fit the binary mode.
+ mode = octal_to_mode (binary_mode);
+ mentioned = (mode & (S_ISUID | S_ISGID)) | S_ISVTX | S_IRWXUGO;
+ return make_node_op_equals (mode, mentioned);
+ }
+
if ('0' <= *mode_string && *mode_string < '8')
{
unsigned int octal_mode = 0;
I would like to receive any feedback on the matter.
Regards,Raphael S.Carvalho
Blog: http://raphaelscarvalho.blogspot.com.br/
Github: https://github.com/raphaelsc
[Prev in Thread] | Current Thread | [Next in Thread] |
---|
- modechange.c (Feature added) - Binary mode support.,Raphael S Carvalho <=
- Prev by Date:Re: cp: when are ACLs copied?
- Next by Date:Re: cp: when are ACLs copied?
- Previous by thread:cp: when are ACLs copied?
- Next by thread:shuf implementation - should/could it be "reservoir sampling "
- Index(es):