alsa.audio: limit the supported frequencies to common set
[AROS.git] / workbench / network / stacks / AROSTCP / netlib / _read.c
blob368abe098c94922f4bd742fc0898366fab03b663
1 /* $Id$
3 * _read.c - read() for both files and sockets (SAS/C)
5 * Copyright © 1994 AmiTCP/IP Group,
6 * Network Solutions Development Inc.
7 * All rights reserved.
8 */
10 #include <ios1.h>
11 #include <stdlib.h>
12 #include <dos.h>
13 #include <string.h>
14 #include <errno.h>
15 #include <dos/dos.h>
16 #include <proto/dos.h>
18 #include <bsdsocket.h>
20 extern int __io2errno(long);
22 int
23 __read(int fd, void *buffer, unsigned int length)
25 struct UFB *ufb;
26 int count;
27 char ch, *ptr, *nextptr, *endptr;
30 * Check for the break signals
32 __chkabort();
34 * find the ufb *
36 if ((ufb = __chkufb(fd)) == NULL) {
37 errno = EINVAL;
38 return -1;
41 * Check if read is allowed
43 if (!(ufb->ufbflg & UFB_RA)) {
44 _OSERR = ERROR_READ_PROTECTED;
45 errno = EIO;
46 return -1;
50 * Do the Actual read
52 _OSERR = 0;
53 if (ufb->ufbflg & UFB_SOCK) {
54 if ((count = recv(fd, (UBYTE *)buffer, length, 0)) < 0) {
55 return -1;
58 else {
59 if ((count = Read(ufb->ufbfh, buffer, length)) == -1) {
60 errno = __io2errno(_OSERR = IoErr());
61 return -1;
65 * Check if translation is not needed
67 if (count == 0 || !(ufb->ufbflg & UFB_XLAT))
68 return count;
70 endptr = (char *)buffer + count; /* first point NOT in buffer */
72 if (endptr[-1] == 0x0D) /* checks last char */
73 #if 0
74 Read(ufb->ufbfh, buffer, 1); /* overwrites first read byte ! */
75 /* BUG ^^^^^^ */
76 #else
77 count--, endptr--;
78 #endif
81 * Remove 0x0D's (CR) (This doesn't remove a CR at the end of the buffer).
83 if ((ptr = memchr(buffer, 0x0D, count)) != NULL) {
84 nextptr = ptr + 1;
85 while (nextptr < endptr) {
86 if ((ch = *nextptr) != 0x0D)
87 *ptr++ = ch;
88 nextptr++;
90 count = ptr - (char *)buffer;
94 * Test for CTRL-Z (end of file)
96 if ((ptr = memchr(buffer, 0x1A, count)) == NULL)
97 return count;
99 return ptr - (char *)buffer;