put.c revision 261194
150477Speter/*
2941Snate * Copyright (c) 2000-2001 Proofpoint, Inc. and its suppliers.
37767Sache *      All rights reserved.
47767Sache * Copyright (c) 1990, 1993
5941Snate *	The Regents of the University of California.  All rights reserved.
674804Sru *
7941Snate * This code is derived from software contributed to Berkeley by
8941Snate * Chris Torek.
9941Snate *
10941Snate * By using this file, you agree to the terms and conditions set
11941Snate * forth in the LICENSE file which can be found at the top level of
12941Snate * the sendmail distribution.
13941Snate */
14226420Sed
15201386Sed#include <sm/gen.h>
1683391SruSM_RCSID("@(#)$Id: put.c,v 1.28 2013/11/22 20:51:43 ca Exp $")
17941Snate#include <string.h>
1874848Sru#include <errno.h>
19941Snate#include <sm/io.h>
2074848Sru#include <sm/assert.h>
2114250Sbde#include <sm/errstring.h>
227767Sache#include <sm/string.h>
237767Sache#include "local.h"
247767Sache#include "fvwrite.h"
257767Sache
267767Sache/*
277767Sache**  SM_IO_PUTC -- output a character to the file
287767Sache**
297767Sache**  Function version of the macro sm_io_putc (in <sm/io.h>).
3074804Sru**
3174848Sru**	Parameters:
3274848Sru**		fp -- file to output to
33**		timeout -- time to complete putc
34**		c -- int value of character to output
35**
36**	Returns:
37**		Failure: returns SM_IO_EOF _and_ sets errno
38**		Success: returns sm_putc() value.
39**
40*/
41
42#undef sm_io_putc
43
44int
45sm_io_putc(fp, timeout, c)
46	SM_FILE_T *fp;
47	int timeout;
48	int c;
49{
50	SM_REQUIRE_ISA(fp, SmFileMagic);
51	if (cantwrite(fp))
52	{
53		errno = EBADF;
54		return SM_IO_EOF;
55	}
56	return sm_putc(fp, timeout, c);
57}
58
59
60/*
61**  SM_PERROR -- print system error messages to smioerr
62**
63**	Parameters:
64**		s -- message to print
65**
66**	Returns:
67**		none
68*/
69
70void
71sm_perror(s)
72	const char *s;
73{
74	int save_errno = errno;
75
76	if (s != NULL && *s != '\0')
77		(void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT, "%s: ", s);
78	(void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT, "%s\n",
79			     sm_errstring(save_errno));
80}
81