diff options
Diffstat (limited to 'examples/hello_strlcpy/hello.c')
-rw-r--r-- | examples/hello_strlcpy/hello.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/examples/hello_strlcpy/hello.c b/examples/hello_strlcpy/hello.c new file mode 100644 index 0000000..b7dd661 --- /dev/null +++ b/examples/hello_strlcpy/hello.c @@ -0,0 +1,25 @@ +#include <stdio.h> +#include <string.h> + +#ifndef HAVE_FUNC3_STRLCPY_STRING_H +size_t strlcpy(char *dst, const char *src, size_t siz); +#endif + +int main (int argc, char ** argv) +{ + char buf [2000]; + char small_buf [10]; + + size_t len; + + while (fgets (buf, sizeof (buf), stdin)){ + len = strlen (buf); + if (len > 0 && buf [len-1] == '\n') + buf [len-1] = 0; + + strlcpy (small_buf, buf, sizeof (small_buf)); + puts (small_buf); + } + + return 0; +} |