ReactOS 0.4.15-dev-8235-gcd88a97
PRead.c
Go to the documentation of this file.
1#include "syshdrs.h"
2
3#if !defined(NO_SIGNALS) && defined(SIGPIPE)
4extern volatile Sjmp_buf gPipeJmp;
5#endif
6
7/* Read up to "size" bytes on sfd.
8 *
9 * If "retry" is on, after a successful read of less than "size"
10 * bytes, it will attempt to read more, upto "size."
11 *
12 * Although "retry" would seem to indicate you may want to always
13 * read "size" bytes or else it is an error, even with that on you
14 * may get back a value < size. Set "retry" to 0 when you want to
15 * return as soon as there is a chunk of data whose size is <= "size".
16 */
17
18int
19PRead(int sfd, char *const buf0, size_t size, int retry)
20{
21 int nread;
22 volatile int nleft;
23 char *volatile buf = buf0;
24#if !defined(NO_SIGNALS) && defined(SIGPIPE)
25 vsio_sigproc_t sigpipe;
26
27 if (SSetjmp(gPipeJmp) != 0) {
28 (void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
29 nread = size - nleft;
30 if (nread > 0)
31 return (nread);
32 errno = EPIPE;
33 return (kBrokenPipeErr);
34 }
35
37#endif
38 errno = 0;
39
40 nleft = (int) size;
41 forever {
42 nread = read(sfd, buf, nleft);
43 if (nread <= 0) {
44 if (nread == 0) {
45 /* EOF */
46 nread = size - nleft;
47 goto done;
48 } else if (errno != EINTR) {
49 nread = size - nleft;
50 if (nread == 0)
51 nread = -1;
52 goto done;
53 } else {
54 errno = 0;
55 nread = 0;
56 /* Try again. */
57 }
58 }
59 nleft -= nread;
60 if ((nleft <= 0) || (retry == 0))
61 break;
62 buf += nread;
63 }
64 nread = size - nleft;
65
66done:
67#if !defined(NO_SIGNALS) && defined(SIGPIPE)
68 (void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe);
69#endif
70 return (nread);
71} /* PRead */
int PRead(int sfd, char *const buf0, size_t size, int retry)
Definition: PRead.c:19
#define EINTR
Definition: acclib.h:80
#define EPIPE
Definition: acclib.h:91
#define read
Definition: acwin.h:96
#define SIGPIPE
Definition: signal.h:35
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
GLsizeiptr size
Definition: glext.h:5919
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define kBrokenPipeErr
Definition: sio.h:59
void SIOHandler(int)
#define SSetjmp(a)
Definition: sio.h:39
volatile sio_sigproc_t vsio_sigproc_t
Definition: sio.h:124
void(*)(int) SSignal(int signum, void(*handler)(int))
Definition: sio.h:237
#define Sjmp_buf
Definition: sio.h:41
void(* sio_sigproc_t)(int)
Definition: sio.h:123
#define forever
Definition: ncftp.h:73
#define errno
Definition: errno.h:18