3 * _write.c - write() for both files and sockets (SAS/C)
5 * Copyright © 1994 AmiTCP/IP Group,
6 * Network Solutions Development Inc.
17 #include <proto/dos.h>
19 #include <bsdsocket.h>
21 extern int __io2errno(long);
24 __write(int fd
, const void *buffer
, unsigned int length
)
31 * Check for the break signals
37 if ((ufb
= __chkufb(fd
)) == NULL
) {
42 * Check if write is allowed
44 if (!(ufb
->ufbflg
& UFB_WA
)) {
45 _OSERR
= ERROR_WRITE_PROTECTED
;
51 * Seek to end of the file if necessary
53 if (ufb
->ufbflg
& UFB_APP
)
57 * Check if translation is not needed
59 if (!(ufb
->ufbflg
& UFB_XLAT
) ||
60 (ptr
= memchr(buffer
, 0x0A, length
)) == NULL
) {
61 if (ufb
->ufbflg
& UFB_SOCK
) {
62 if ((count
= send(fd
, (char *)buffer
, length
, 0)) < 0)
66 if ((count
= Write(ufb
->ufbfh
, (void *)buffer
, length
)) == -1)
75 * Translate, ie., append CR before each LF
78 count
= ptr
- (char *)buffer
;
79 if (ufb
->ufbflg
& UFB_SOCK
) {
80 if (send(fd
, (char *)buffer
, count
, 0) < 0)
82 if (send(fd
, "\015"/* CR */, 1, 0) < 0)
86 if (Write(ufb
->ufbfh
, (void *)buffer
, count
) == -1)
88 if (Write(ufb
->ufbfh
, "\015"/* CR */, 1) == -1)
94 } while ((ptr
= memchr((char *)buffer
+ 1, 0x0A, length
)) != NULL
);
96 if (ufb
->ufbflg
& UFB_SOCK
) {
97 if ((count
= send(fd
, (char *)buffer
, length
, 0)) < 0)
101 if (Write(ufb
->ufbfh
, (void *)buffer
, length
) == -1)
108 errno
= __io2errno(_OSERR
= IoErr());