diff options
author | Andrew Shadura <andrew@shadura.me> | 2015-07-25 14:44:54 +0200 |
---|---|---|
committer | Andrew Shadura <andrew@shadura.me> | 2015-07-25 14:44:54 +0200 |
commit | 7bea690e43ee009efc9e8f6a45504496348cd3ee (patch) | |
tree | 4e958845f208f3398e3a5bbf7532199ee49a4989 /examples/hello_compatlib/prog1/prog1.c | |
parent | 8d15cbf39b8aa01eaabfa3167e6ce3dc9f9e0af8 (diff) |
Imported Upstream version 0.28.0
Diffstat (limited to 'examples/hello_compatlib/prog1/prog1.c')
-rw-r--r-- | examples/hello_compatlib/prog1/prog1.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/examples/hello_compatlib/prog1/prog1.c b/examples/hello_compatlib/prog1/prog1.c new file mode 100644 index 0000000..b662024 --- /dev/null +++ b/examples/hello_compatlib/prog1/prog1.c @@ -0,0 +1,38 @@ +#include <stdio.h> +#include <string.h> + +#include <mkc_strlcpy.h> +#include <mkc_strlcat.h> +#include <mkc_getline.h> +#include <mkc_progname.h> + +static const char message [] = "Theo de Raadt said: \"The strlcpy() and strlcat() functions provide a consistent, unambiguous API to help the programmer write more bullet-proof code.\""; + +int main (int argc, char ** argv) +{ + char *buf = NULL; + size_t size = 0; + ssize_t len = 0; + char small_buf [15]; + char said [19]; + + setprogname (argv [0]); + + while (len = getline (&buf, &size, stdin), len != -1){ + len = strlen (buf); + if (len > 0 && buf [len-1] == '\n') + buf [len-1] = 0; + + strlcpy (small_buf, "foo17", sizeof (small_buf)); + strlcat (small_buf, buf, sizeof (small_buf)); + puts (small_buf); + } + + strlcpy (said, message, sizeof (said)); + puts (said); + + printf ("short progname=%s\n", getprogname ()); + printf ("full progname=%s\n", argv [0]); + + return 0; +} |