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;

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]