mirror of
https://github.com/reactos/reactos.git
synced 2025-02-25 01:39:30 +00:00
ws2_32_new compatibility fixes
- Fix the rest of the code which was using errno instead of WSAGetLastError() - Remove some dead code svn path=/trunk/; revision=42188
This commit is contained in:
parent
daba4d6880
commit
adb1a3f3c8
4 changed files with 46 additions and 125 deletions
|
@ -1540,7 +1540,7 @@ rewrite_client_leases(struct interface_info *ifi)
|
|||
if (!leaseFile) {
|
||||
leaseFile = fopen(path_dhclient_db, "w");
|
||||
if (!leaseFile)
|
||||
error("can't create %s: %s", path_dhclient_db, strerror(errno));
|
||||
error("can't create %s", path_dhclient_db);
|
||||
} else {
|
||||
fflush(leaseFile);
|
||||
rewind(leaseFile);
|
||||
|
@ -1577,7 +1577,7 @@ write_client_lease(struct interface_info *ip, struct client_lease *lease,
|
|||
if (!leaseFile) { /* XXX */
|
||||
leaseFile = fopen(path_dhclient_db, "w");
|
||||
if (!leaseFile)
|
||||
error("can't create %s: %s", path_dhclient_db, strerror(errno));
|
||||
error("can't create %s", path_dhclient_db);
|
||||
}
|
||||
|
||||
fprintf(leaseFile, "lease {\n");
|
||||
|
@ -1632,7 +1632,7 @@ script_init(char *reason, struct string_list *medium)
|
|||
sizeof(size_t) + strlen(reason);
|
||||
|
||||
if ((buf = buf_open(hdr.len)) == NULL)
|
||||
error("buf_open: %s", strerror(errno));
|
||||
return;
|
||||
|
||||
errs = 0;
|
||||
errs += buf_add(buf, &hdr, sizeof(hdr));
|
||||
|
@ -1644,10 +1644,10 @@ script_init(char *reason, struct string_list *medium)
|
|||
errs += buf_add(buf, reason, len);
|
||||
|
||||
if (errs)
|
||||
error("buf_add: %s", strerror(errno));
|
||||
error("buf_add: %d", WSAGetLastError());
|
||||
|
||||
if (buf_close(privfd, buf) == -1)
|
||||
error("buf_close: %s", strerror(errno));
|
||||
error("buf_close: %d", WSAGetLastError());
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -1822,7 +1822,7 @@ script_write_params(char *prefix, struct client_lease *lease)
|
|||
scripttime = time(NULL);
|
||||
|
||||
if ((buf = buf_open(hdr.len)) == NULL)
|
||||
error("buf_open: %s", strerror(errno));
|
||||
return;
|
||||
|
||||
errs = 0;
|
||||
errs += buf_add(buf, &hdr, sizeof(hdr));
|
||||
|
@ -1842,10 +1842,10 @@ script_write_params(char *prefix, struct client_lease *lease)
|
|||
}
|
||||
|
||||
if (errs)
|
||||
error("buf_add: %s", strerror(errno));
|
||||
error("buf_add: %d", WSAGetLastError());
|
||||
|
||||
if (buf_close(privfd, buf) == -1)
|
||||
error("buf_close: %s", strerror(errno));
|
||||
error("buf_close: %d", WSAGetLastError());
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -2075,41 +2075,3 @@ toobig:
|
|||
return "<error>";
|
||||
}
|
||||
|
||||
#if 0
|
||||
int
|
||||
fork_privchld(int fd, int fd2)
|
||||
{
|
||||
struct pollfd pfd[1];
|
||||
int nfds;
|
||||
|
||||
switch (fork()) {
|
||||
case -1:
|
||||
error("cannot fork");
|
||||
case 0:
|
||||
break;
|
||||
default:
|
||||
return (0);
|
||||
}
|
||||
|
||||
setproctitle("%s [priv]", ifi->name);
|
||||
|
||||
dup2(nullfd, STDIN_FILENO);
|
||||
dup2(nullfd, STDOUT_FILENO);
|
||||
dup2(nullfd, STDERR_FILENO);
|
||||
close(nullfd);
|
||||
close(fd2);
|
||||
|
||||
for (;;) {
|
||||
pfd[0].fd = fd;
|
||||
pfd[0].events = POLLIN;
|
||||
if ((nfds = poll(pfd, 1, INFTIM)) == -1)
|
||||
if (errno != EINTR)
|
||||
error("poll error");
|
||||
|
||||
if (nfds == 0 || !(pfd[0].revents & POLLIN))
|
||||
continue;
|
||||
|
||||
dispatch_imsg(fd);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -198,8 +198,8 @@ got_one(struct protocol *l)
|
|||
|
||||
if ((result = receive_packet(ip, u.packbuf, sizeof(u), &from,
|
||||
&hfrom)) == -1) {
|
||||
warning("receive_packet failed on %s: %s", ip->name,
|
||||
strerror(errno));
|
||||
warning("receive_packet failed on %s: %d", ip->name,
|
||||
WSAGetLastError());
|
||||
ip->errors++;
|
||||
if (ip->errors > 20) {
|
||||
/* our interface has gone away. */
|
||||
|
@ -374,33 +374,5 @@ find_protocol_by_adapter(struct interface_info *info)
|
|||
int
|
||||
interface_link_status(char *ifname)
|
||||
{
|
||||
#if 0
|
||||
struct ifmediareq ifmr;
|
||||
int sock;
|
||||
|
||||
if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
|
||||
error("Can't create socket");
|
||||
|
||||
memset(&ifmr, 0, sizeof(ifmr));
|
||||
strlcpy(ifmr.ifm_name, ifname, sizeof(ifmr.ifm_name));
|
||||
if (ioctl(sock, SIOCGIFMEDIA, (caddr_t)&ifmr) == -1) {
|
||||
/* EINVAL -> link state unknown. treat as active */
|
||||
if (errno != EINVAL)
|
||||
syslog(LOG_DEBUG, "ioctl(SIOCGIFMEDIA) on %s: %m",
|
||||
ifname);
|
||||
close(sock);
|
||||
return (1);
|
||||
}
|
||||
close(sock);
|
||||
|
||||
if (ifmr.ifm_status & IFM_AVALID) {
|
||||
if ((ifmr.ifm_active & IFM_NMASK) == IFM_ETHER) {
|
||||
if (ifmr.ifm_status & IFM_ACTIVE)
|
||||
return (1);
|
||||
else
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return (1);
|
||||
}
|
||||
|
|
|
@ -98,7 +98,6 @@ struct udphdr {
|
|||
#include <sys/stat.h>
|
||||
//#include <sys/time.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
//#include <unistd.h>
|
||||
|
|
|
@ -52,19 +52,16 @@ buf_close(int sock, struct buf *buf)
|
|||
{
|
||||
ssize_t n;
|
||||
|
||||
do {
|
||||
n = write(sock, buf->buf + buf->rpos, buf->size - buf->rpos);
|
||||
if (n != -1)
|
||||
buf->rpos += n;
|
||||
if (n == 0) { /* connection closed */
|
||||
errno = 0;
|
||||
return (-1);
|
||||
}
|
||||
} while (n == -1 && (errno == EAGAIN || errno == EINTR));
|
||||
n = write(sock, buf->buf + buf->rpos, buf->size - buf->rpos);
|
||||
if (n != -1)
|
||||
buf->rpos += n;
|
||||
if (n == 0) { /* connection closed */
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (buf->rpos < buf->size)
|
||||
error("short %s write: wanted %lu got %ld bytes",
|
||||
strerror(errno), (unsigned long)buf->size, (long)buf->rpos);
|
||||
error("short write: wanted %lu got %ld bytes",
|
||||
(unsigned long)buf->size, (long)buf->rpos);
|
||||
|
||||
free(buf->buf);
|
||||
free(buf);
|
||||
|
@ -77,19 +74,17 @@ buf_read(int sock, void *buf, size_t nbytes)
|
|||
ssize_t n, r = 0;
|
||||
char *p = buf;
|
||||
|
||||
do {
|
||||
n = read(sock, p, nbytes);
|
||||
if (n == 0)
|
||||
error("connection closed");
|
||||
if (n != -1) {
|
||||
r += n;
|
||||
p += n;
|
||||
nbytes -= n;
|
||||
}
|
||||
} while (n == -1 && (errno == EINTR || errno == EAGAIN));
|
||||
n = read(sock, p, nbytes);
|
||||
if (n == 0)
|
||||
error("connection closed");
|
||||
if (n != -1) {
|
||||
r += n;
|
||||
p += n;
|
||||
nbytes -= n;
|
||||
}
|
||||
|
||||
if (n == -1)
|
||||
error("buf_read: %s", strerror(errno));
|
||||
error("buf_read: %d", WSAGetLastError());
|
||||
|
||||
if (r < nbytes)
|
||||
error("short read: wanted %lu got %ld bytes",
|
||||
|
@ -121,9 +116,8 @@ dispatch_imsg(int fd)
|
|||
+ sizeof(size_t) || medium_len == SIZE_T_MAX)
|
||||
error("corrupted message received");
|
||||
if (medium_len > 0) {
|
||||
if ((medium = calloc(1, medium_len + 1)) == NULL)
|
||||
error("%s", strerror(errno));
|
||||
buf_read(fd, medium, medium_len);
|
||||
if ((medium = calloc(1, medium_len + 1)) != NULL)
|
||||
buf_read(fd, medium, medium_len);
|
||||
} else
|
||||
medium = NULL;
|
||||
|
||||
|
@ -132,9 +126,8 @@ dispatch_imsg(int fd)
|
|||
reason_len == SIZE_T_MAX)
|
||||
error("corrupted message received");
|
||||
if (reason_len > 0) {
|
||||
if ((reason = calloc(1, reason_len + 1)) == NULL)
|
||||
error("%s", strerror(errno));
|
||||
buf_read(fd, reason, reason_len);
|
||||
if ((reason = calloc(1, reason_len + 1)) != NULL)
|
||||
buf_read(fd, reason, reason_len);
|
||||
} else
|
||||
reason = NULL;
|
||||
|
||||
|
@ -155,9 +148,8 @@ dispatch_imsg(int fd)
|
|||
if (hdr.len < totlen || filename_len == SIZE_T_MAX)
|
||||
error("corrupted message received");
|
||||
if (filename_len > 0) {
|
||||
if ((filename = calloc(1, filename_len + 1)) == NULL)
|
||||
error("%s", strerror(errno));
|
||||
buf_read(fd, filename, filename_len);
|
||||
if ((filename = calloc(1, filename_len + 1)) != NULL)
|
||||
buf_read(fd, filename, filename_len);
|
||||
} else
|
||||
filename = NULL;
|
||||
|
||||
|
@ -167,9 +159,8 @@ dispatch_imsg(int fd)
|
|||
error("corrupted message received");
|
||||
if (servername_len > 0) {
|
||||
if ((servername =
|
||||
calloc(1, servername_len + 1)) == NULL)
|
||||
error("%s", strerror(errno));
|
||||
buf_read(fd, servername, servername_len);
|
||||
calloc(1, servername_len + 1)) != NULL)
|
||||
buf_read(fd, servername, servername_len);
|
||||
} else
|
||||
servername = NULL;
|
||||
|
||||
|
@ -178,9 +169,8 @@ dispatch_imsg(int fd)
|
|||
if (hdr.len < totlen || prefix_len == SIZE_T_MAX)
|
||||
error("corrupted message received");
|
||||
if (prefix_len > 0) {
|
||||
if ((prefix = calloc(1, prefix_len + 1)) == NULL)
|
||||
error("%s", strerror(errno));
|
||||
buf_read(fd, prefix, prefix_len);
|
||||
if ((prefix = calloc(1, prefix_len + 1)) != NULL)
|
||||
buf_read(fd, prefix, prefix_len);
|
||||
} else
|
||||
prefix = NULL;
|
||||
|
||||
|
@ -197,9 +187,8 @@ dispatch_imsg(int fd)
|
|||
error("corrupted message received");
|
||||
lease.options[i].data =
|
||||
calloc(1, optlen + 1);
|
||||
if (lease.options[i].data == NULL)
|
||||
error("%s", strerror(errno));
|
||||
buf_read(fd, lease.options[i].data, optlen);
|
||||
if (lease.options[i].data != NULL)
|
||||
buf_read(fd, lease.options[i].data, optlen);
|
||||
}
|
||||
}
|
||||
lease.server_name = servername;
|
||||
|
@ -222,14 +211,13 @@ dispatch_imsg(int fd)
|
|||
|
||||
hdr.code = IMSG_SCRIPT_GO_RET;
|
||||
hdr.len = sizeof(struct imsg_hdr) + sizeof(int);
|
||||
if ((buf = buf_open(hdr.len)) == NULL)
|
||||
error("buf_open: %s", strerror(errno));
|
||||
if (buf_add(buf, &hdr, sizeof(hdr)))
|
||||
error("buf_add: %s", strerror(errno));
|
||||
if (buf_add(buf, &ret, sizeof(ret)))
|
||||
error("buf_add: %s", strerror(errno));
|
||||
if (buf_close(fd, buf) == -1)
|
||||
error("buf_close: %s", strerror(errno));
|
||||
buf = buf_open(hdr.len);
|
||||
|
||||
if (buf != NULL) {
|
||||
buf_add(buf, &hdr, sizeof(hdr));
|
||||
buf_add(buf, &ret, sizeof(ret));
|
||||
buf_close(fd, buf);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
error("received unknown message, code %d", hdr.code);
|
||||
|
|
Loading…
Reference in a new issue