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 #include <sm/gen.h>
16*7c478bd9Sstevel@tonic-gate SM_RCSID("@(#)$Id: put.c,v 1.27 2001/12/19 05:19:35 ca Exp $")
17*7c478bd9Sstevel@tonic-gate #include <string.h>
18*7c478bd9Sstevel@tonic-gate #include <errno.h>
19*7c478bd9Sstevel@tonic-gate #include <sm/io.h>
20*7c478bd9Sstevel@tonic-gate #include <sm/assert.h>
21*7c478bd9Sstevel@tonic-gate #include <sm/errstring.h>
22*7c478bd9Sstevel@tonic-gate #include <sm/string.h>
23*7c478bd9Sstevel@tonic-gate #include "local.h"
24*7c478bd9Sstevel@tonic-gate #include "fvwrite.h"
25*7c478bd9Sstevel@tonic-gate
26*7c478bd9Sstevel@tonic-gate /*
27*7c478bd9Sstevel@tonic-gate ** SM_IO_PUTC -- output a character to the file
28*7c478bd9Sstevel@tonic-gate **
29*7c478bd9Sstevel@tonic-gate ** Function version of the macro sm_io_putc (in <sm/io.h>).
30*7c478bd9Sstevel@tonic-gate **
31*7c478bd9Sstevel@tonic-gate ** Parameters:
32*7c478bd9Sstevel@tonic-gate ** fp -- file to output to
33*7c478bd9Sstevel@tonic-gate ** timeout -- time to complete putc
34*7c478bd9Sstevel@tonic-gate ** c -- int value of character to output
35*7c478bd9Sstevel@tonic-gate **
36*7c478bd9Sstevel@tonic-gate ** Returns:
37*7c478bd9Sstevel@tonic-gate ** Failure: returns SM_IO_EOF _and_ sets errno
38*7c478bd9Sstevel@tonic-gate ** Success: returns sm_putc() value.
39*7c478bd9Sstevel@tonic-gate **
40*7c478bd9Sstevel@tonic-gate */
41*7c478bd9Sstevel@tonic-gate
42*7c478bd9Sstevel@tonic-gate #undef sm_io_putc
43*7c478bd9Sstevel@tonic-gate
44*7c478bd9Sstevel@tonic-gate int
45*7c478bd9Sstevel@tonic-gate sm_io_putc(fp, timeout, c)
46*7c478bd9Sstevel@tonic-gate SM_FILE_T *fp;
47*7c478bd9Sstevel@tonic-gate int timeout;
48*7c478bd9Sstevel@tonic-gate int c;
49*7c478bd9Sstevel@tonic-gate {
50*7c478bd9Sstevel@tonic-gate SM_REQUIRE_ISA(fp, SmFileMagic);
51*7c478bd9Sstevel@tonic-gate if (cantwrite(fp))
52*7c478bd9Sstevel@tonic-gate {
53*7c478bd9Sstevel@tonic-gate errno = EBADF;
54*7c478bd9Sstevel@tonic-gate return SM_IO_EOF;
55*7c478bd9Sstevel@tonic-gate }
56*7c478bd9Sstevel@tonic-gate return sm_putc(fp, timeout, c);
57*7c478bd9Sstevel@tonic-gate }
58*7c478bd9Sstevel@tonic-gate
59*7c478bd9Sstevel@tonic-gate
60*7c478bd9Sstevel@tonic-gate /*
61*7c478bd9Sstevel@tonic-gate ** SM_PERROR -- print system error messages to smioerr
62*7c478bd9Sstevel@tonic-gate **
63*7c478bd9Sstevel@tonic-gate ** Parameters:
64*7c478bd9Sstevel@tonic-gate ** s -- message to print
65*7c478bd9Sstevel@tonic-gate **
66*7c478bd9Sstevel@tonic-gate ** Returns:
67*7c478bd9Sstevel@tonic-gate ** none
68*7c478bd9Sstevel@tonic-gate */
69*7c478bd9Sstevel@tonic-gate
70*7c478bd9Sstevel@tonic-gate void
sm_perror(s)71*7c478bd9Sstevel@tonic-gate sm_perror(s)
72*7c478bd9Sstevel@tonic-gate const char *s;
73*7c478bd9Sstevel@tonic-gate {
74*7c478bd9Sstevel@tonic-gate int save_errno = errno;
75*7c478bd9Sstevel@tonic-gate
76*7c478bd9Sstevel@tonic-gate if (s != NULL && *s != '\0')
77*7c478bd9Sstevel@tonic-gate (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT, "%s: ", s);
78*7c478bd9Sstevel@tonic-gate (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT, "%s\n",
79*7c478bd9Sstevel@tonic-gate sm_errstring(save_errno));
80*7c478bd9Sstevel@tonic-gate }
81