xref: /titanic_50/usr/src/cmd/sendmail/libsm/put.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * Copyright (c) 2000-2001 Sendmail, Inc. and its suppliers.
3*7c478bd9Sstevel@tonic-gate  *      All rights reserved.
4*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1990, 1993
5*7c478bd9Sstevel@tonic-gate  *	The Regents of the University of California.  All rights reserved.
6*7c478bd9Sstevel@tonic-gate  *
7*7c478bd9Sstevel@tonic-gate  * This code is derived from software contributed to Berkeley by
8*7c478bd9Sstevel@tonic-gate  * Chris Torek.
9*7c478bd9Sstevel@tonic-gate  *
10*7c478bd9Sstevel@tonic-gate  * By using this file, you agree to the terms and conditions set
11*7c478bd9Sstevel@tonic-gate  * forth in the LICENSE file which can be found at the top level of
12*7c478bd9Sstevel@tonic-gate  * the sendmail distribution.
13*7c478bd9Sstevel@tonic-gate  */
14*7c478bd9Sstevel@tonic-gate 
15*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
16*7c478bd9Sstevel@tonic-gate 
17*7c478bd9Sstevel@tonic-gate #include <sm/gen.h>
18*7c478bd9Sstevel@tonic-gate SM_RCSID("@(#)$Id: put.c,v 1.27 2001/12/19 05:19:35 ca Exp $")
19*7c478bd9Sstevel@tonic-gate #include <string.h>
20*7c478bd9Sstevel@tonic-gate #include <errno.h>
21*7c478bd9Sstevel@tonic-gate #include <sm/io.h>
22*7c478bd9Sstevel@tonic-gate #include <sm/assert.h>
23*7c478bd9Sstevel@tonic-gate #include <sm/errstring.h>
24*7c478bd9Sstevel@tonic-gate #include <sm/string.h>
25*7c478bd9Sstevel@tonic-gate #include "local.h"
26*7c478bd9Sstevel@tonic-gate #include "fvwrite.h"
27*7c478bd9Sstevel@tonic-gate 
28*7c478bd9Sstevel@tonic-gate /*
29*7c478bd9Sstevel@tonic-gate **  SM_IO_PUTC -- output a character to the file
30*7c478bd9Sstevel@tonic-gate **
31*7c478bd9Sstevel@tonic-gate **  Function version of the macro sm_io_putc (in <sm/io.h>).
32*7c478bd9Sstevel@tonic-gate **
33*7c478bd9Sstevel@tonic-gate **	Parameters:
34*7c478bd9Sstevel@tonic-gate **		fp -- file to output to
35*7c478bd9Sstevel@tonic-gate **		timeout -- time to complete putc
36*7c478bd9Sstevel@tonic-gate **		c -- int value of character to output
37*7c478bd9Sstevel@tonic-gate **
38*7c478bd9Sstevel@tonic-gate **	Returns:
39*7c478bd9Sstevel@tonic-gate **		Failure: returns SM_IO_EOF _and_ sets errno
40*7c478bd9Sstevel@tonic-gate **		Success: returns sm_putc() value.
41*7c478bd9Sstevel@tonic-gate **
42*7c478bd9Sstevel@tonic-gate */
43*7c478bd9Sstevel@tonic-gate 
44*7c478bd9Sstevel@tonic-gate #undef sm_io_putc
45*7c478bd9Sstevel@tonic-gate 
46*7c478bd9Sstevel@tonic-gate int
47*7c478bd9Sstevel@tonic-gate sm_io_putc(fp, timeout, c)
48*7c478bd9Sstevel@tonic-gate 	SM_FILE_T *fp;
49*7c478bd9Sstevel@tonic-gate 	int timeout;
50*7c478bd9Sstevel@tonic-gate 	int c;
51*7c478bd9Sstevel@tonic-gate {
52*7c478bd9Sstevel@tonic-gate 	SM_REQUIRE_ISA(fp, SmFileMagic);
53*7c478bd9Sstevel@tonic-gate 	if (cantwrite(fp))
54*7c478bd9Sstevel@tonic-gate 	{
55*7c478bd9Sstevel@tonic-gate 		errno = EBADF;
56*7c478bd9Sstevel@tonic-gate 		return SM_IO_EOF;
57*7c478bd9Sstevel@tonic-gate 	}
58*7c478bd9Sstevel@tonic-gate 	return sm_putc(fp, timeout, c);
59*7c478bd9Sstevel@tonic-gate }
60*7c478bd9Sstevel@tonic-gate 
61*7c478bd9Sstevel@tonic-gate 
62*7c478bd9Sstevel@tonic-gate /*
63*7c478bd9Sstevel@tonic-gate **  SM_PERROR -- print system error messages to smioerr
64*7c478bd9Sstevel@tonic-gate **
65*7c478bd9Sstevel@tonic-gate **	Parameters:
66*7c478bd9Sstevel@tonic-gate **		s -- message to print
67*7c478bd9Sstevel@tonic-gate **
68*7c478bd9Sstevel@tonic-gate **	Returns:
69*7c478bd9Sstevel@tonic-gate **		none
70*7c478bd9Sstevel@tonic-gate */
71*7c478bd9Sstevel@tonic-gate 
72*7c478bd9Sstevel@tonic-gate void
sm_perror(s)73*7c478bd9Sstevel@tonic-gate sm_perror(s)
74*7c478bd9Sstevel@tonic-gate 	const char *s;
75*7c478bd9Sstevel@tonic-gate {
76*7c478bd9Sstevel@tonic-gate 	int save_errno = errno;
77*7c478bd9Sstevel@tonic-gate 
78*7c478bd9Sstevel@tonic-gate 	if (s != NULL && *s != '\0')
79*7c478bd9Sstevel@tonic-gate 		(void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT, "%s: ", s);
80*7c478bd9Sstevel@tonic-gate 	(void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT, "%s\n",
81*7c478bd9Sstevel@tonic-gate 			     sm_errstring(save_errno));
82*7c478bd9Sstevel@tonic-gate }
83