use BUFSIZ for optimal buffer size, check open return fd - sdhcp - simple dhcp client
 (HTM) git clone git://git.codemadness.org/sdhcp
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) LICENSE
       ---
 (DIR) commit ba2f7b64cceb89657c54733fbfdfb0b127427da1
 (DIR) parent 6d5cb4daf78d159d9a6446183956c7a7086f1b80
 (HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org>
       Date:   Fri, 25 Apr 2014 22:02:37 +0200
       
       use BUFSIZ for optimal buffer size, check open return fd
       
       Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>
       
       Diffstat:
         M sdhcp.c                             |      12 ++++++------
       
       1 file changed, 6 insertions(+), 6 deletions(-)
       ---
 (DIR) 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