diff options
Diffstat (limited to 'examples/hello_strlcpy')
-rw-r--r-- | examples/hello_strlcpy/Makefile | 12 | ||||
-rw-r--r-- | examples/hello_strlcpy/expect.out | 93 | ||||
-rw-r--r-- | examples/hello_strlcpy/getline.c | 67 | ||||
-rw-r--r-- | examples/hello_strlcpy/hello.c | 30 | ||||
-rw-r--r-- | examples/hello_strlcpy/input.in | 23 | ||||
-rw-r--r-- | examples/hello_strlcpy/strlcpy.c | 51 | ||||
-rw-r--r-- | examples/hello_strlcpy/test.mk | 38 |
7 files changed, 0 insertions, 314 deletions
diff --git a/examples/hello_strlcpy/Makefile b/examples/hello_strlcpy/Makefile deleted file mode 100644 index f24ed5a..0000000 --- a/examples/hello_strlcpy/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -MKC_SOURCE_FUNCLIBS = strlcpy getline -MKC_CHECK_FUNCS3 += strlcpy:string.h getline:stdio.h - -PROG = hello -SRCS = hello.c - -WARNS = 4 - -MKC_REQD = 0.10.0 - -.include "test.mk" -.include <mkc.prog.mk> diff --git a/examples/hello_strlcpy/expect.out b/examples/hello_strlcpy/expect.out deleted file mode 100644 index 8acecb6..0000000 --- a/examples/hello_strlcpy/expect.out +++ /dev/null @@ -1,93 +0,0 @@ -# Copyrig -# All rig -# -# Redistr -# modific -# are met -# 1. Redi -# noti -# 2. Redi -# noti -# docu -# -# THIS SO -# ``AS IS -# TO, THE -# PURPOSE -# BE LIAB -# CONSEQU -# SUBSTIT -# INTERRU -# CONTRAC -# ARISING -# POSSIBI -=========== all ============ -/objdir/Makefile -/objdir/_mkc_compiler_type.err -/objdir/_mkc_compiler_type.res -/objdir/_mkc_func3_getline_stdio_h.c -/objdir/_mkc_func3_getline_stdio_h.err -/objdir/_mkc_func3_getline_stdio_h.res -/objdir/_mkc_func3_strlcpy_string_h.c -/objdir/_mkc_func3_strlcpy_string_h.err -/objdir/_mkc_func3_strlcpy_string_h.res -/objdir/_mkc_funclib_getline.c -/objdir/_mkc_funclib_getline.err -/objdir/_mkc_funclib_getline.res -/objdir/_mkc_funclib_strlcpy.c -/objdir/_mkc_funclib_strlcpy.err -/objdir/_mkc_funclib_strlcpy.res -/objdir/_mkc_prog_cc.err -/objdir/_mkc_prog_cc.res -/objdir/expect.out -/objdir/getline.c -/objdir/hello -/objdir/hello.c -/objdir/hello.o -/objdir/hello_strlcpy.test.out.tmp -/objdir/input.in -/objdir/strlcpy.c -/objdir/test.mk -========= install ========== -/objdir/prefix -/objdir/prefix/bin -/objdir/prefix/bin/hello -======== uninstall ========= -========== clean =========== -/objdir/Makefile -/objdir/_mkc_compiler_type.err -/objdir/_mkc_compiler_type.res -/objdir/_mkc_func3_getline_stdio_h.c -/objdir/_mkc_func3_getline_stdio_h.err -/objdir/_mkc_func3_getline_stdio_h.res -/objdir/_mkc_func3_strlcpy_string_h.c -/objdir/_mkc_func3_strlcpy_string_h.err -/objdir/_mkc_func3_strlcpy_string_h.res -/objdir/_mkc_funclib_getline.c -/objdir/_mkc_funclib_getline.err -/objdir/_mkc_funclib_getline.res -/objdir/_mkc_funclib_strlcpy.c -/objdir/_mkc_funclib_strlcpy.err -/objdir/_mkc_funclib_strlcpy.res -/objdir/_mkc_prog_cc.err -/objdir/_mkc_prog_cc.res -/objdir/expect.out -/objdir/getline.c -/objdir/hello.c -/objdir/hello_strlcpy.test.out.tmp -/objdir/input.in -/objdir/strlcpy.c -/objdir/test.mk -======= distclean ========== -/objdir/Makefile -/objdir/expect.out -/objdir/getline.c -/objdir/hello.c -/objdir/hello_strlcpy.test.out.tmp -/objdir/input.in -/objdir/strlcpy.c -/objdir/test.mk -======= CLEANFILES ========== -hello.o -strlcpy.o -getline.o diff --git a/examples/hello_strlcpy/getline.c b/examples/hello_strlcpy/getline.c deleted file mode 100644 index 669c1ab..0000000 --- a/examples/hello_strlcpy/getline.c +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2007-2013 Aleksey Cheusov <vle@gmx.net> - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -#include <stdio.h> -#include <stdlib.h> - -ssize_t -getline(char** lineptr, size_t* n, FILE* stream); - -ssize_t -getline(char** lineptr, size_t* n, FILE* stream) -{ - int c; - size_t sz = 0; - - while (c = getc (stream), c != EOF){ - if (sz+1 >= *n){ - /* +2 is for `c' and 0-terminator */ - *n = *n * 3 / 2 + 2; - *lineptr = (char *) realloc (*lineptr, *n); - if (!*lineptr) - return -1; - } - - (*lineptr) [sz++] = (char) c; - if (c == '\n') - break; - } - - if (ferror (stream)) - return (ssize_t) -1; - - if (!sz){ - if (feof (stream)){ - return (ssize_t) -1; - }else if (!*n){ - *lineptr = (char *) malloc (1); - if (!*lineptr) - return -1; - - *n = 1; - } - } - - (*lineptr) [sz] = 0; - return sz; -} diff --git a/examples/hello_strlcpy/hello.c b/examples/hello_strlcpy/hello.c deleted file mode 100644 index 1ec6315..0000000 --- a/examples/hello_strlcpy/hello.c +++ /dev/null @@ -1,30 +0,0 @@ -#include <stdio.h> -#include <string.h> -#include <stdlib.h> - -#ifndef HAVE_FUNC3_STRLCPY_STRING_H -size_t strlcpy(char *dst, const char *src, size_t siz); -#endif - -#ifndef HAVE_FUNC3_GETLINE_STDIO_H -ssize_t getline(char** lineptr, size_t* n, FILE* stream); -#endif - -int main (int argc, char ** argv) -{ - char *buf = NULL; - size_t size = 0; - ssize_t len = 0; - char small_buf [10]; - - 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, buf, sizeof (small_buf)); - puts (small_buf); - } - - return 0; -} diff --git a/examples/hello_strlcpy/input.in b/examples/hello_strlcpy/input.in deleted file mode 100644 index a5a6836..0000000 --- a/examples/hello_strlcpy/input.in +++ /dev/null @@ -1,23 +0,0 @@ -# Copyright (c) 2009, Aleksey Cheusov <vle@gmx.net> -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS -# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED -# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS -# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. diff --git a/examples/hello_strlcpy/strlcpy.c b/examples/hello_strlcpy/strlcpy.c deleted file mode 100644 index c7f1fbb..0000000 --- a/examples/hello_strlcpy/strlcpy.c +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND TODD C. MILLER DISCLAIMS ALL - * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL TODD C. MILLER BE LIABLE - * FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION - * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -/* - * Copy src to string dst of size siz. At most siz-1 characters - * will be copied. Always NUL terminates (unless siz == 0). - * Returns strlen(src); if retval >= siz, truncation occurred. - */ -#include <string.h> - -size_t -strlcpy(char *dst, const char *src, size_t siz); - -size_t -strlcpy(char *dst, const char *src, size_t siz) -{ - char *d = dst; - const char *s = src; - size_t n = siz; - - /* Copy as many bytes as will fit */ - if (n != 0 && --n != 0) { - do { - if ((*d++ = *s++) == 0) - break; - } while (--n != 0); - } - - /* Not enough room in dst, add NUL and traverse rest of src */ - if (n == 0) { - if (siz != 0) - *d = '\0'; /* NUL-terminate dst */ - while (*s++) - ; - } - - return(s - src - 1); /* count does not include NUL */ -} diff --git a/examples/hello_strlcpy/test.mk b/examples/hello_strlcpy/test.mk deleted file mode 100644 index 29a6e51..0000000 --- a/examples/hello_strlcpy/test.mk +++ /dev/null @@ -1,38 +0,0 @@ -.PHONY : test_output -test_output: - @set -e; \ - ${.OBJDIR}/hello < ${.CURDIR}/input.in; \ - rm -rf ${.OBJDIR}${PREFIX}; \ - MKCATPAGES=yes; export MKCATPAGES; \ - \ - echo =========== all ============; \ - find ${.OBJDIR} -type f | grep -Ev '(strlcpy|getline)[.]o' | \ - mkc_test_helper "${PREFIX}" "${.OBJDIR}"; \ - \ - echo ========= install ==========; \ - ${MAKE} ${MAKEFLAGS} install -j3 DESTDIR=${.OBJDIR} \ - > /dev/null; \ - find ${.OBJDIR}${PREFIX} -type f -o -type d | \ - grep -vE '(strlcpy|getline)[.]o' | \ - mkc_test_helper "${PREFIX}" "${.OBJDIR}"; \ - \ - echo ======== uninstall =========; \ - ${MAKE} ${MAKEFLAGS} -j4 uninstall DESTDIR=${.OBJDIR} > /dev/null; \ - find ${.OBJDIR}${PREFIX} -type f | grep -vE '(strlcpy|getline)[.]o' | \ - mkc_test_helper "${PREFIX}" "${.OBJDIR}"; \ - \ - echo ========== clean ===========; \ - ${MAKE} ${MAKEFLAGS} clean > /dev/null; \ - find ${.OBJDIR} -type f | grep -vE '(strlcpy|getline)[.]o' | \ - mkc_test_helper "${PREFIX}" "${.OBJDIR}"; \ - \ - echo ======= distclean ==========; \ - ${MAKE} ${MAKEFLAGS} distclean > /dev/null; \ - find ${.OBJDIR} -type f | grep -vE '(strlcpy|getline)[.]o' | \ - mkc_test_helper "${PREFIX}" "${.OBJDIR}"; \ - \ - echo ======= CLEANFILES ==========; \ - ${MAKE} ${MAKEFLAGS} print_values VARS='CLEANFILES' MKCHECKS=no | \ - awk '{for(i=1; i<=NF; ++i) if ($$i ~ /[.]o.?$$/) print $$i}' - -.include <mkc.minitest.mk> |