5 ms·
What's even more interesting is to see how much code is needed in the GNU true. http://git.savannah.gnu.org/cgit/coreutils.git/tree/src/true.c http://git.savan
by wnissen 9y ago
What's even more interesting is to see how much code is needed in the GNU true.
http://git.savannah.gnu.org/cgit/coreutils.git/tree/src/true.c http://git.savannah.gnu.org/cgit/coreutils.git/tree/src/true...
4 includes, 3 ifdefs or define blocks, the whole thing is 80 lines, more than half of it code!
- ilanco 9y agoLooks like most of the code is processing the arguments.
- paulddraper 9y agoIt is. -h, -v
- jwilk 9y ago--help, --version. Short options are not recognized.
- belorn 9y agoSince those are just for argument parsing, should we not also include the extra code that the kernel run in order for proper execution? With that we can even include additional stuff like apparmor adding code to protect against exploits in True. I suspect that each invocation to True, regardless of implementation, spend in average a large amount of unnecessary cpu instruction for practically every OS.
- ams6110 9y agoBy comparison, OpenBSD's version: /* $OpenBSD: true.c,v 1.1 2015/11/11 19:05:28 deraadt Exp $ */ /* Public domain - Theo de Raadt */ int main(int argc, char *argv[]) { return (0); }
- kobeya 9y agoWhich is, actually, far too large due to the standard library, program state initialization, and stack frame management. If there's ever a practical use for code golf, this is probably it. /bin/true should be a bare minimum ELF executable with no stack or heap that does nothing except immediately make the system call to terminate.
- cat199 9y agoAs mentioned in the article: " This can be done with an empty file that's marked executable, and that's what it was in the earliest unix system libraries. " $ uname -sr OpenBSD 6.1 $ install -m 755 /dev/null /tmp/muhtrue && /tmp/muhtrue && echo yup yup not sure why it was ever switched.. probably the 'return 0;' version is cheaper than a shell fork? hmm..
- slezyr 9y agoWell this code might do exactly what you just said. Everything depends with which compiler flags you build this code. I know for sure there are MSVS flags to build this program with no runtime and other things with just return asm op in it.
- ben_bai 9y agoMost likely nobody uses /bin/true (/usr/bin/true). Executing true without the pathname will run the shell embedded function.
- smhenderson 9y agoBut it implements true and false!
- Maakuth 9y agoThis is thought to be because of GNU Coding Standards: https://www.gnu.org/prep/standards/standards.html#Reading-Non_002dFree-Code https://www.gnu.org/prep/standards/standards.html#Reading-No... They wanted GNU implementers to be careful not to copy (even through their recall) AT&T UNIX implementation, but to do compatible solutions in different way. This allowed them to keep safe footing legally through the time when the original UNIX source code's copyright status wasn't clear. The point of the GNU project is to create independent UNIX compatible operating system. The BSD implementations are often referred in this discussion, but regarding them, you've got to keep in mind that it is continuation of the original UNIX source tree, after it's copyright status was clarified (https://en.wikipedia.org/wiki/UNIX_System_Laboratories,_Inc._v._Berkeley_Software_Design,_Inc. https://en.wikipedia.org/wiki/UNIX_System_Laboratories,_Inc....).