diff options
author | gshapiro <gshapiro@FreeBSD.org> | 2013-04-21 17:08:44 +0000 |
---|---|---|
committer | gshapiro <gshapiro@FreeBSD.org> | 2013-04-21 17:08:44 +0000 |
commit | 891f1b61da33280fa1ba153569b360771d27e984 (patch) | |
tree | ab52d50bcac2932bf5e37126b12ef0d2886488f1 /contrib/sendmail/libsm | |
parent | 84dd41acc62e69379821ee9ff4d6461233543f07 (diff) | |
parent | a03b7e14eaaeb30fff6859c589152c8787d230e3 (diff) | |
download | FreeBSD-src-891f1b61da33280fa1ba153569b360771d27e984.zip FreeBSD-src-891f1b61da33280fa1ba153569b360771d27e984.tar.gz |
Merge sendmail 8.14.7 to HEAD
MFC after: 4 days
Diffstat (limited to 'contrib/sendmail/libsm')
-rw-r--r-- | contrib/sendmail/libsm/Makefile.m4 | 3 | ||||
-rw-r--r-- | contrib/sendmail/libsm/cf.c | 4 | ||||
-rw-r--r-- | contrib/sendmail/libsm/fget.c | 29 | ||||
-rw-r--r-- | contrib/sendmail/libsm/t-fget.c | 86 |
4 files changed, 106 insertions, 16 deletions
diff --git a/contrib/sendmail/libsm/Makefile.m4 b/contrib/sendmail/libsm/Makefile.m4 index da5dd55..4c7f637 100644 --- a/contrib/sendmail/libsm/Makefile.m4 +++ b/contrib/sendmail/libsm/Makefile.m4 @@ -1,4 +1,4 @@ -dnl $Id: Makefile.m4,v 1.72 2006/08/16 21:06:31 ca Exp $ +dnl $Id: Makefile.m4,v 1.73 2013/03/12 15:24:50 ca Exp $ define(`confREQUIRE_LIBUNIX') include(confBUILDTOOLSDIR`/M4/switch.m4') @@ -18,6 +18,7 @@ smcheck(`t-exc', `compile-run') smcheck(`t-rpool', `compile-run') smcheck(`t-string', `compile-run') smcheck(`t-smstdio', `compile-run') +smcheck(`t-fget', `compile-run') smcheck(`t-match', `compile-run') smcheck(`t-strio', `compile-run') smcheck(`t-heap', `compile-run') diff --git a/contrib/sendmail/libsm/cf.c b/contrib/sendmail/libsm/cf.c index d217875..6501c05 100644 --- a/contrib/sendmail/libsm/cf.c +++ b/contrib/sendmail/libsm/cf.c @@ -9,7 +9,7 @@ */ #include <sm/gen.h> -SM_RCSID("@(#)$Id: cf.c,v 1.6 2001/09/11 04:04:47 gshapiro Exp $") +SM_RCSID("@(#)$Id: cf.c,v 1.7 2013/03/12 15:24:50 ca Exp $") #include <ctype.h> #include <errno.h> @@ -54,7 +54,7 @@ sm_cf_getopt(path, optc, optv) if (cfp == NULL) return errno; - while (sm_io_fgets(cfp, SM_TIME_DEFAULT, buf, sizeof(buf)) != NULL) + while (sm_io_fgets(cfp, SM_TIME_DEFAULT, buf, sizeof(buf)) >= 0) { p = strchr(buf, '\n'); if (p != NULL) diff --git a/contrib/sendmail/libsm/fget.c b/contrib/sendmail/libsm/fget.c index 611748c..01c49da 100644 --- a/contrib/sendmail/libsm/fget.c +++ b/contrib/sendmail/libsm/fget.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000-2001 Sendmail, Inc. and its suppliers. + * Copyright (c) 2000-2001, 2013 Sendmail, Inc. and its suppliers. * All rights reserved. * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -13,7 +13,7 @@ */ #include <sm/gen.h> -SM_RCSID("@(#)$Id: fget.c,v 1.24 2001/09/11 04:04:48 gshapiro Exp $") +SM_RCSID("@(#)$Id: fget.c,v 1.25 2013/03/12 15:24:50 ca Exp $") #include <stdlib.h> #include <string.h> #include <sm/io.h> @@ -33,31 +33,32 @@ SM_RCSID("@(#)$Id: fget.c,v 1.24 2001/09/11 04:04:48 gshapiro Exp $") ** n -- size of 'buf' ** ** Returns: -** success: returns value of 'buf' -** failure: NULL (no characters were read) -** timeout: NULL and errno set to EAGAIN +** success: number of characters +** failure: -1 +** timeout: -1 and errno set to EAGAIN ** ** Side Effects: ** may move the file pointer */ -char * +int sm_io_fgets(fp, timeout, buf, n) register SM_FILE_T *fp; int timeout; char *buf; register int n; { - register int len; - register char *s; - register unsigned char *p, *t; + int len, r; + char *s; + unsigned char *p, *t; SM_REQUIRE_ISA(fp, SmFileMagic); if (n <= 0) /* sanity check */ - return NULL; + return -1; s = buf; n--; /* leave space for NUL */ + r = 0; while (n > 0) { /* If the buffer is empty, refill it. */ @@ -73,7 +74,7 @@ sm_io_fgets(fp, timeout, buf, n) { /* EOF/error: stop with partial or no line */ if (s == buf) - return NULL; + return -1; break; } len = fp->f_r; @@ -93,18 +94,20 @@ sm_io_fgets(fp, timeout, buf, n) if (t != NULL) { len = ++t - p; + r += len; fp->f_r -= len; fp->f_p = t; (void) memcpy((void *) s, (void *) p, len); s[len] = 0; - return buf; + return r; } fp->f_r -= len; fp->f_p += len; (void) memcpy((void *) s, (void *) p, len); s += len; + r += len; n -= len; } *s = 0; - return buf; + return r; } diff --git a/contrib/sendmail/libsm/t-fget.c b/contrib/sendmail/libsm/t-fget.c new file mode 100644 index 0000000..434debf --- /dev/null +++ b/contrib/sendmail/libsm/t-fget.c @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2013 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-fget.c,v 1.1 2013/03/12 15:24:50 ca Exp $") + +#include <sm/io.h> +#include <sm/string.h> +#include <sm/test.h> +#include <errno.h> + +void +check(char *msg, int l) +{ + SM_FILE_T *wfp, *rfp; + char buf[256]; + size_t n; + int r, i; + static char fn[] = "tfget"; + + wfp = sm_io_open(SmFtStdio, SM_TIME_DEFAULT, fn, + SM_IO_WRONLY_B, NULL); + SM_TEST(wfp != NULL); + for (i = 0; i < l; i++) + { + r = sm_io_putc(wfp, SM_TIME_DEFAULT, msg[i]); + SM_TEST(r >= 0); + } + r = sm_io_close(wfp, SM_TIME_DEFAULT); + SM_TEST(r == 0); + + rfp = sm_io_open(SmFtStdio, SM_TIME_DEFAULT, fn, + SM_IO_RDONLY_B, NULL); + SM_TEST(rfp != NULL); + n = sizeof(buf); + r = sm_io_fgets(rfp, SM_TIME_DEFAULT, buf, n); + if (l == 0) + { + SM_TEST(r == -1); + SM_TEST(errno == 0); + } + else + { + SM_TEST(r == l); + if (r != l) + fprintf(stderr, "buf='%s', in='%s', r=%d, l=%d\n", + buf, msg, r, l); + } + SM_TEST(memcmp(buf, msg, l) == 0); + r = sm_io_close(rfp, SM_TIME_DEFAULT); + SM_TEST(r == 0); +} + + +int +main(argc, argv) + int argc; + char **argv; +{ + char res[256]; + int l; + + sm_test_begin(argc, argv, "test fget"); + + check("", strlen("")); + check("\n", strlen("\n")); + check("test\n", strlen("test\n")); + + l = snprintf(res, sizeof(res), "%c%s\n", '\0', "test ing"); + check(res, l); + + l = snprintf(res, sizeof(res), "%c%s%c\n", '\0', "test ing", '\0'); + check(res, l); + + l = snprintf(res, sizeof(res), "%c%s%c%s\n", + '\0', "test ing", '\0', "eol"); + check(res, l); + + return sm_test_end(); +} |