This patch fixes most of current reasons to generate compiler warnings. The changes consist of: - adding missing casts - hiding or unhiding function declarations - including headers where missing - add __UNCONST when assigning a const char * to a char * - adding missing return statements - changing some types from unsigned to signed, as the code seems to want signed ints - converting old-style function definitions to current style (i.e., void func(param1, param2) short param1, param2; {...} to void func (short param1, short param2) {...}) - making the compiler silent about signed vs unsigned comparisons. We have too many of those in the new libc to fix. A number of bugs in the test set were fixed. These bugs were never triggered with our old libc. Consequently, these tests are now forced to link with the new libc or they will generate errors (in particular tests 43 and 55). Most changes in NetBSD libc are limited to moving aroudn "#ifndef __minix" or stuff related to Minix-specific things (code in sys-minix or gen/minix).
49 lines
1.1 KiB
C
49 lines
1.1 KiB
C
/* asyn_write() Author: Kees J. Bot
|
|
* 7 Jul 1997
|
|
*/
|
|
#include "asyn.h"
|
|
#include <signal.h>
|
|
|
|
ssize_t asyn_write(asynchio_t *asyn, int fd, const void *buf, size_t len)
|
|
/* Nonblocking write(). (See asyn_read()). */
|
|
{
|
|
asynfd_t *afd;
|
|
|
|
asyn->asyn_more++;
|
|
|
|
if ((unsigned) fd >= FD_SETSIZE) { errno= EBADF; return -1; }
|
|
afd= &asyn->asyn_afd[fd];
|
|
|
|
if (!afd->afd_seen) {
|
|
if ((afd->afd_flags= fcntl(fd, F_GETFL)) < 0) return -1;
|
|
afd->afd_seen= 1;
|
|
}
|
|
|
|
if (afd->afd_state[SEL_WRITE] == PENDING) {
|
|
sigset_t mask;
|
|
ssize_t result;
|
|
int err;
|
|
|
|
sigemptyset(&mask);
|
|
if (sigprocmask(SIG_SETMASK, &mask, &mask) < 0) return -1;
|
|
(void) fcntl(fd, F_SETFL, afd->afd_flags | O_NONBLOCK);
|
|
|
|
result= write(fd, buf, len);
|
|
err= errno;
|
|
|
|
(void) fcntl(fd, F_SETFL, afd->afd_flags);
|
|
(void) sigprocmask(SIG_SETMASK, &mask, nil);
|
|
|
|
errno= err;
|
|
if (result != -1 || errno != EAGAIN) {
|
|
afd->afd_state[SEL_WRITE]= IDLE;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
afd->afd_state[SEL_WRITE]= WAITING;
|
|
FD_SET(fd, &asyn->asyn_fdset[SEL_WRITE]);
|
|
errno= EAGAIN;
|
|
asyn->asyn_more--;
|
|
return -1;
|
|
}
|