diff options
author | gshapiro <gshapiro@FreeBSD.org> | 2002-02-17 21:56:45 +0000 |
---|---|---|
committer | gshapiro <gshapiro@FreeBSD.org> | 2002-02-17 21:56:45 +0000 |
commit | 8449595fe97f4474b9b9a7e4edee1ef35dcff393 (patch) | |
tree | e7a33b132264d449a512ddf4a8685df097669c1d /contrib/sendmail/libsm/t-smstdio.c | |
parent | 289b381b31415647269c7520d881017e2dcb27f1 (diff) | |
download | FreeBSD-src-8449595fe97f4474b9b9a7e4edee1ef35dcff393.zip FreeBSD-src-8449595fe97f4474b9b9a7e4edee1ef35dcff393.tar.gz |
Import sendmail 8.12.2
Diffstat (limited to 'contrib/sendmail/libsm/t-smstdio.c')
-rw-r--r-- | contrib/sendmail/libsm/t-smstdio.c | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/contrib/sendmail/libsm/t-smstdio.c b/contrib/sendmail/libsm/t-smstdio.c new file mode 100644 index 0000000..3bad1c1 --- /dev/null +++ b/contrib/sendmail/libsm/t-smstdio.c @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2000-2001 Sendmail, Inc. and its suppliers. + * All rights reserved. + * + * By using this file, you agree to the terms and conditions set + * forth in the LICENSE file which can be found at the top level of + * the sendmail distribution. + */ + +#include <sm/gen.h> +SM_IDSTR(id, "@(#)$Id: t-smstdio.c,v 1.11 2001/09/11 04:04:49 gshapiro Exp $") + +#include <sm/io.h> +#include <sm/string.h> +#include <sm/test.h> + +int +main(argc, argv) + int argc; + char **argv; +{ + FILE *stream; + SM_FILE_T *fp; + char buf[128]; + size_t n; + static char testmsg[] = "hello, world\n"; + + sm_test_begin(argc, argv, + "test sm_io_stdioopen, smiostdin, smiostdout"); + + stream = fopen("t-smstdio.1", "w"); + SM_TEST(stream != NULL); + + fp = sm_io_stdioopen(stream, "w"); + SM_TEST(fp != NULL); + + (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%s", testmsg); + sm_io_close(fp, SM_TIME_DEFAULT); + +#if 0 + /* + ** stream should now be closed. This is a tricky way to test + ** if it is still open. Alas, it core dumps on Linux. + */ + + fprintf(stream, "oops! stream is still open!\n"); + fclose(stream); +#endif + + stream = fopen("t-smstdio.1", "r"); + SM_TEST(stream != NULL); + + fp = sm_io_stdioopen(stream, "r"); + SM_TEST(fp != NULL); + + n = sm_io_read(fp, SM_TIME_DEFAULT, buf, sizeof(buf)); + if (SM_TEST(n == strlen(testmsg))) + { + buf[n] = '\0'; + SM_TEST(strcmp(buf, testmsg) == 0); + } + +#if 0 + + /* + ** Copy smiostdin to smiostdout + ** gotta think some more about how to test smiostdin and smiostdout + */ + + while ((c = sm_io_getc(smiostdin)) != SM_IO_EOF) + sm_io_putc(smiostdout, c); +#endif + + return sm_test_end(); +} |