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