source: trunk/third/sendmail/libsm/t-scanf.c @ 19204

Revision 19204, 1.4 KB checked in by zacheiss, 22 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r19203, which included commits to RCS files with non-trunk default branches.
Line 
1/*
2 * Copyright (c) 2001 Sendmail, Inc. and its suppliers.
3 *      All rights reserved.
4 *
5 * By using this file, you agree to the terms and conditions set
6 * forth in the LICENSE file which can be found at the top level of
7 * the sendmail distribution.
8 */
9
10#include <sm/gen.h>
11SM_IDSTR(id, "@(#)$Id: t-scanf.c,v 1.1.1.1 2003-04-08 15:06:32 zacheiss Exp $")
12
13#include <sm/limits.h>
14#include <sm/io.h>
15#include <sm/string.h>
16#include <sm/test.h>
17#include <sm/types.h>
18
19int
20main(argc, argv)
21        int argc;
22        char **argv;
23{
24        int i, d, h;
25        char buf[128];
26        char *r;
27
28        sm_test_begin(argc, argv, "test scanf point stuff");
29#if !SM_CONF_BROKEN_SIZE_T
30        (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
31"If tests for \"h == 2\" fail, check whether size_t is signed on your OS.\n\
32If that is the case, add -DSM_CONF_BROKEN_SIZE_T to confENVDEF\n\
33and start over. Otherwise contact sendmail.org.\n");
34#endif /* !SM_CONF_BROKEN_SIZE_T */
35
36        d = 2;
37        sm_snprintf(buf, sizeof(buf), "%d", d);
38        r = "2";
39        if (!SM_TEST(strcmp(buf, r) == 0))
40                (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
41                                     "got %s instead\n", buf);
42
43        i = sm_io_sscanf(buf, "%d", &h);
44        SM_TEST(i == 1);
45        SM_TEST(h == 2);
46
47        d = 2;
48        sm_snprintf(buf, sizeof(buf), "%d\n", d);
49        r = "2\n";
50        if (!SM_TEST(strcmp(buf, r) == 0))
51                (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
52                                     "got %s instead\n", buf);
53
54        i = sm_io_sscanf(buf, "%d", &h);
55        SM_TEST(i == 1);
56        SM_TEST(h == 2);
57
58        return sm_test_end();
59}
Note: See TracBrowser for help on using the repository browser.