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!
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!
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....).
/* $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);
}" 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..Of course the system could have special cased a zero length executable file.
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.
Executing true without the pathname will run the shell embedded function.
I suspect that each invocation to True, regardless of implementation, spend in average a large amount of unnecessary cpu instruction for practically every OS.