diff options
Diffstat (limited to 'src/regress/lib/libc/time/strptime/main.c')
| -rw-r--r-- | src/regress/lib/libc/time/strptime/main.c | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/src/regress/lib/libc/time/strptime/main.c b/src/regress/lib/libc/time/strptime/main.c new file mode 100644 index 0000000000..d1d9c394a5 --- /dev/null +++ b/src/regress/lib/libc/time/strptime/main.c | |||
| @@ -0,0 +1,117 @@ | |||
| 1 | /* $OpenBSD: main.c,v 1.1 2004/01/20 16:47:56 millert Exp $ */ | ||
| 2 | /* $NetBSD: main.c,v 1.4 2002/02/21 07:38:18 itojun Exp $ */ | ||
| 3 | |||
| 4 | /*- | ||
| 5 | * Copyright (c) 1998 The NetBSD Foundation, Inc. | ||
| 6 | * All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * 1. Redistributions of source code must retain the above copyright | ||
| 12 | * notice, this list of conditions and the following disclaimer. | ||
| 13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 14 | * notice, this list of conditions and the following disclaimer in the | ||
| 15 | * documentation and/or other materials provided with the distribution. | ||
| 16 | * 3. All advertising materials mentioning features or use of this software | ||
| 17 | * must display the following acknowledgement: | ||
| 18 | * This product includes software developed by the NetBSD | ||
| 19 | * Foundation, Inc. and its contributors. | ||
| 20 | * 4. Neither the name of The NetBSD Foundation nor the names of its | ||
| 21 | * contributors may be used to endorse or promote products derived | ||
| 22 | * from this software without specific prior written permission. | ||
| 23 | * | ||
| 24 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
| 25 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
| 26 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 27 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
| 28 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
| 29 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
| 30 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
| 31 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
| 32 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 33 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| 34 | * POSSIBILITY OF SUCH DAMAGE. | ||
| 35 | */ | ||
| 36 | #include <err.h> | ||
| 37 | #include <stdio.h> | ||
| 38 | #include <stdlib.h> | ||
| 39 | #include <string.h> | ||
| 40 | #include <time.h> | ||
| 41 | |||
| 42 | int main(int, char *[]); | ||
| 43 | void die(void); | ||
| 44 | |||
| 45 | void | ||
| 46 | die(void) | ||
| 47 | { | ||
| 48 | |||
| 49 | if (ferror(stdin)) | ||
| 50 | err(1, "fgetln"); | ||
| 51 | else | ||
| 52 | errx(1, "input is truncated"); | ||
| 53 | } | ||
| 54 | |||
| 55 | int | ||
| 56 | main(int argc, char *argv[]) | ||
| 57 | { | ||
| 58 | char *p, *title, *buf, *format; | ||
| 59 | size_t len; | ||
| 60 | struct tm tm; | ||
| 61 | |||
| 62 | for (;;) { | ||
| 63 | p = fgetln(stdin, &len); | ||
| 64 | if (p == 0) | ||
| 65 | die(); | ||
| 66 | title = malloc(len + 1); | ||
| 67 | memcpy(title, p, len); | ||
| 68 | title[len] = '\0'; | ||
| 69 | |||
| 70 | if (!strcmp(title, "EOF\n")) | ||
| 71 | return(0); | ||
| 72 | if (title[0] == '#' || title[0] == '\n') { | ||
| 73 | free(title); | ||
| 74 | continue; | ||
| 75 | } | ||
| 76 | |||
| 77 | p = fgetln(stdin, &len); | ||
| 78 | if (p == 0) | ||
| 79 | die(); | ||
| 80 | buf = malloc(len + 1); | ||
| 81 | memcpy(buf, p, len); | ||
| 82 | buf[len] = '\0'; | ||
| 83 | |||
| 84 | p = fgetln(stdin, &len); | ||
| 85 | if (p == 0) | ||
| 86 | die(); | ||
| 87 | format = malloc(len + 1); | ||
| 88 | memcpy(format, p, len); | ||
| 89 | format[len] = '\0'; | ||
| 90 | |||
| 91 | tm.tm_sec = -1; | ||
| 92 | tm.tm_min = -1; | ||
| 93 | tm.tm_hour = -1; | ||
| 94 | tm.tm_mday = -1; | ||
| 95 | tm.tm_mon = -1; | ||
| 96 | tm.tm_year = -1; | ||
| 97 | tm.tm_wday = -1; | ||
| 98 | tm.tm_yday = -1; | ||
| 99 | |||
| 100 | p = strptime(buf, format, &tm); | ||
| 101 | |||
| 102 | printf("%s", title); | ||
| 103 | if (p) { | ||
| 104 | printf("succeeded\n"); | ||
| 105 | printf("%d %d %d %d %d %d %d %d\n", | ||
| 106 | tm.tm_sec, tm.tm_min, tm.tm_hour, tm.tm_mday, | ||
| 107 | tm.tm_mon, tm.tm_year, tm.tm_wday, tm.tm_yday); | ||
| 108 | printf("%s\n", p); | ||
| 109 | } else { | ||
| 110 | printf("failed\n"); | ||
| 111 | } | ||
| 112 | |||
| 113 | free(title); | ||
| 114 | free(buf); | ||
| 115 | free(format); | ||
| 116 | } | ||
| 117 | } | ||
