sdhcp

simple dhcp client
git clone git://git.2f30.org/sdhcp.git
Log | Files | Refs | LICENSE

commit ba2f7b64cceb89657c54733fbfdfb0b127427da1
parent 6d5cb4daf78d159d9a6446183956c7a7086f1b80
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Fri Apr 25 22:02:37 +0200

use BUFSIZ for optimal buffer size, check open return fd

Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>

Diffstat:
sdhcp.c | 12++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/sdhcp.c b/sdhcp.c @@ -171,14 +171,14 @@ setip(unsigned char ip[4], unsigned char mask[4], unsigned char gateway[4]) static void cat(int dfd, char *src) { - char buf[4096]; /* TODO: use BUFSIZ ? */ - int n, sfd = open(src, O_RDONLY); + char buf[BUFSIZ]; + int n, fd; - while((n = read(sfd, buf, sizeof buf))>0) + if((fd = open(src, O_RDONLY)) == -1) + return; /* can't read, but don't error out */ + while((n = read(fd, buf, sizeof buf)) > 0) write(dfd, buf, n); - close(sfd); - -} + close(fd); } static void