[PATCH] mesg.c: make tty variable use only dynamic memory
gotrunks at gmail.com
gotrunks at gmail.com
Tue Mar 22 09:01:00 UTC 2011
On Tue, Mar 22, 2011 at 6:52 AM, Denys Vlasenko
<vda.linux at googlemail.com> wrote:
> On Tuesday 22 March 2011 00:47, Tito wrote:
>> attached as drop in replacement file a alternative version with:
>> 1) better command line options checking (catches yx error)
>> 2) size reduction
>> function old new delta
>> fchmod - 31 +31
>> __fchmod - 31 +31
>> bb_perror_nomsg_and_die - 9 +9
>> mesg_main 174 158 -16
>> chmod 31 - -31
>> __chmod 31 - -31
>> ------------------------------------------------------------------------------
>> (add/remove: 4/2 grow/shrink: 0/1 up/down: 71/-78) Total: -7 bytes
>> 3) better error messages
>> 4) no dynamically allocated memory
>>
>> it is just a proof of concept and little tested but seems to work.
>> If there is interest I can make a patch.
>> Hints, critics and improvements are welcome.
>
> Thanks, I used your idea while making USE_TTY_GROUP thing configurable.
>
You can save 2 bytes reversing some logic:
xfstat(STDERR_FILENO, &sb, "stderr");
if (c != 0) {
m = (c == 'y') ? sb.st_mode | S_IWGRP_OR_S_IWOTH
: sb.st_mode & ~(S_IWGRP|S_IWOTH);
if (fchmod(STDERR_FILENO, m) != 0)
bb_perror_nomsg_and_die();
} else
puts((sb.st_mode & (S_IWGRP|S_IWOTH)) ? "is y" : "is n");
return EXIT_SUCCESS;
function old new delta
mesg_main 155 153 -2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-2) Total: -2 bytes
Regards,
--
Pere
More information about the busybox
mailing list