2 * Copyright (c) 2000-2001 Sendmail, Inc. and its suppliers.
4 * Copyright (c) 1990, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
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.
15 #pragma ident "%Z%%M% %I% %E% SMI"
18 SM_RCSID("@(#)$Id: fread.c,v 1.26 2001/02/28 20:54:03 ca Exp $")
22 #include <sm/assert.h>
26 ** SM_IO_READ -- read data from the file pointer
29 ** fp -- file pointer to read from
30 ** timeout -- time to complete the read
31 ** buf -- location to place read data
32 ** size -- size of each chunk of data
35 ** Failure: returns 0 (zero) _and_ sets errno
36 ** Success: returns the number of whole chunks read.
38 ** A read returning 0 (zero) is only an indication of error when errno
43 sm_io_read(fp
, timeout
, buf
, size
)
49 register size_t resid
= size
;
53 SM_REQUIRE_ISA(fp
, SmFileMagic
);
55 if (fp
->f_read
== NULL
)
62 ** The ANSI standard requires a return value of 0 for a count
63 ** or a size of 0. Peculiarily, it imposes no such requirements
64 ** on fwrite; it only requires read to be broken.
72 while ((int) resid
> (r
= fp
->f_r
))
74 (void) memcpy((void *) p
, (void *) fp
->f_p
, (size_t) r
);
76 /* fp->f_r = 0 ... done in sm_refill */
79 if ((fp
->f_flags
& SMNOW
) != 0 && r
> 0)
82 ** Take whatever we have available. Spend no more time
83 ** trying to get all that has been requested.
84 ** This is needed on some file types (such as
85 ** SASL) that would jam when given extra, untimely
92 if (sm_refill(fp
, timeout
) != 0)
94 /* no more input: return partial result */
98 (void) memcpy((void *) p
, (void *) fp
->f_p
, resid
);