diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2003-05-15 04:23:50 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2003-05-15 04:23:50 +0000 |
commit | 218491df8f24346a79dac3ef3f9d93554e0570d5 (patch) | |
tree | 44272f59872efd5dd0edb886ff5bdb72e3fdd522 /regress/lib/libc | |
parent | 1e682631379497118377160f89cfaa774c4ed1ae (diff) |
first sprintf test: positional args
Diffstat (limited to 'regress/lib/libc')
-rw-r--r-- | regress/lib/libc/Makefile | 4 | ||||
-rw-r--r-- | regress/lib/libc/sprintf/Makefile | 10 | ||||
-rw-r--r-- | regress/lib/libc/sprintf/sprintf_test.c | 80 |
3 files changed, 92 insertions, 2 deletions
diff --git a/regress/lib/libc/Makefile b/regress/lib/libc/Makefile index e8c5809eb6f..1861062bbed 100644 --- a/regress/lib/libc/Makefile +++ b/regress/lib/libc/Makefile @@ -1,8 +1,8 @@ -# $OpenBSD: Makefile,v 1.10 2003/02/12 06:49:04 mickey Exp $ +# $OpenBSD: Makefile,v 1.11 2003/05/15 04:23:49 deraadt Exp $ SUBDIR+= alloca SUBDIR+= _setjmp db getaddrinfo regex setjmp sigsetjmp malloc sigreturn popen -SUBDIR+= longjmp atexit +SUBDIR+= longjmp atexit sprintf .if (${MACHINE_ARCH} != "vax") SUBDIR+= ieeefp .endif diff --git a/regress/lib/libc/sprintf/Makefile b/regress/lib/libc/sprintf/Makefile new file mode 100644 index 00000000000..47bab9cdd36 --- /dev/null +++ b/regress/lib/libc/sprintf/Makefile @@ -0,0 +1,10 @@ +# $OpenBSD: Makefile,v 1.1 2003/05/15 04:23:49 deraadt Exp $ + +NOMAN= +PROG=sprintf_test +CPPFLAGS+=-I${.CURDIR}/../../../../lib/libc + +run-regress-atexit_test: ${PROG} + ./${PROG} + +.include <bsd.regress.mk> diff --git a/regress/lib/libc/sprintf/sprintf_test.c b/regress/lib/libc/sprintf/sprintf_test.c new file mode 100644 index 00000000000..1387b2970e4 --- /dev/null +++ b/regress/lib/libc/sprintf/sprintf_test.c @@ -0,0 +1,80 @@ +/* $OpenBSD: sprintf_test.c,v 1.1 2003/05/15 04:23:49 deraadt Exp $ */ + +/* + * Copyright (c) 2003 Theo de Raadt + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - 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 COPYRIGHT HOLDERS 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 + * COPYRIGHT HOLDERS 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. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <signal.h> + +char correct[] = + "|xx 01 02 03 04\n" + "|xx 05 06 07 08\n" + "|xx 09 10 11 12\n" + "|xx 13 14 15 16\n" + "|xx 17 18 19 20\n" + "|xx 21 22 23 24\n" + "|xx 25 26 27 28\n" + "|xx 29 30 31 32\n" + "|xx 33 34 35 36\n" + "|xx 37 38 39 40\n" + "|xx 41 42 43 44\n"; + +int +main(int argc, char *argv[]) +{ + char buf[1024]; + + /* Test positional arguments */ + snprintf(buf, sizeof buf, + "|xx %1$s %2$s %3$s %4$s\n" + "|xx %5$s %6$s %7$s %8$s\n" + "|xx %9$s %10$s %11$s %12$s\n" + "|xx %13$s %14$s %15$s %16$s\n" + "|xx %17$s %18$s %19$s %20$s\n" + "|xx %21$s %22$s %23$s %24$s\n" + "|xx %25$s %26$s %27$s %28$s\n" + "|xx %29$s %30$s %31$s %32$s\n" + "|xx %33$s %34$s %35$s %36$s\n" + "|xx %37$s %38$s %39$s %40$s\n" + "|xx %41$s %42$s %43$s %44$s\n", + "01", "02", "03", "04", "05", "06", + "07", "08", "09", "10", "11", "12", + "13", "14", "15", "16", "17", "18", + "19", "20", "21", "22", "23", "24", + "25", "26", "27", "28", "29", "30", + "31", "32", "33", "34", "35", "36", + "37", "38", "39", "40", "41", "42", + "43", "44" + ); + + if (strcmp(buf, correct) == 0) + exit(0); + exit(1); +} |