'I happened to be sitting next to Bill Joy at UCB when he wrote the first "yes"'

3 days ago 3

@@ -44,20 +44,42 @@ static const char rcsid[] = "$FreeBSD$";

4444

#include <capsicum_helpers.h>

4545

#include <err.h>

4646

#include <stdio.h>

47+

#include <string.h>

48+

#include <unistd.h>

47494850

int

4951

main(int argc, char **argv)

5052

{

53+

char buf[8192];

54+

char y[2] = { 'y', '\n' };

55+

char * exp = y;

56+

size_t buflen = 0;

57+

size_t explen = sizeof(y);

51585259

if (caph_limit_stdio() < 0 || (cap_enter() < 0 && errno != ENOSYS))

5360

err(1, "capsicum");

54615562

if (argc > 1)

56-

while (puts(argv[1]) != EOF)

57-

;

58-

else

59-

while (puts("y") != EOF)

60-

;

63+

{

64+

exp = argv[1];

65+

explen = strlen(exp) + 1;

66+

exp[explen - 1] = '\n';

67+

}

68+69+

if (explen <= sizeof(buf))

70+

{

71+

while (buflen < sizeof(buf) - explen)

72+

{

73+

memcpy(buf + buflen, exp, explen);

74+

buflen += explen;

75+

}

76+

exp = buf;

77+

explen = buflen;

78+

}

79+80+

while (write(STDOUT_FILENO, exp, explen) > 0)

81+

;

82+6183

err(1, "stdout");

6284

/*NOTREACHED*/

6385

}

Read Entire Article