From 1d647a3018a73e9736e02c42685b18d23fea5b11 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Thu, 1 Apr 2004 17:01:18 +0000 Subject: clean --- lib/update.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/update.c b/lib/update.c index a599180..f510861 100644 --- a/lib/update.c +++ b/lib/update.c @@ -27,10 +27,12 @@ #include #include #include +#include #include "unzip.h" #include -#define DATFILE "tarife" +#define DATFILE "tarife.zip" +#define BUF_SIZ 1024 const char *TGebURL = "www.billiger-telefonieren.de"; const char *TGebGET = "GET /downloads/tgeb/tarife_%.4i%.2i%.2i.zip HTTP/1.0\n\n"; @@ -64,24 +66,24 @@ tgeb_update(struct tm * tm) sizeof(struct sockaddr))) == -1) err(1, "connect"); - if (!(get = malloc(sizeof(char) * strlen(TGebGET)))) + if (!(get = calloc(strlen(TGebGET), sizeof(char)))) err(1, "malloc"); sprintf(get, TGebGET, tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday); if ((send(sockfd, get, strlen(get), NULL)) == -1) err(1, "send"); free(get); - if (!(buf = malloc(sizeof(char) * 1024))) + if (!(buf = calloc(BUF_SIZ, sizeof(char)))) err(1, "malloc"); for (;;) { int block; - if ((block = recv(sockfd, &buf[offset], 1024, NULL)) == -1) + if ((block = recv(sockfd, &buf[offset], BUF_SIZ, NULL)) == -1) err(1, "recv"); if (block == 0) break; offset += block; - if (!(buf = realloc(buf, offset + 1024))) + if (!(buf = realloc(buf, offset + BUF_SIZ))) err(1, "malloc"); } close(sockfd); @@ -104,25 +106,30 @@ unzip(void) unzFile *unzfd; unz_global_info gi; unz_file_info fi; - char FileName[256]; - char buf[1024]; + char FileName[_POSIX_PATH_MAX]; + char *buf; int i, len; if (!(unzfd = unzOpen(DATFILE))) errx(1, "unzOpen %s", DATFILE); unzGetGlobalInfo(unzfd, &gi); + + if (!(buf = calloc(BUF_SIZ, sizeof(char)))) + err(1, "malloc"); + for (i = 0; i < gi.number_entry; i++) { unzGetCurrentFileInfo(unzfd, &fi, FileName, sizeof(FileName), NULL, 0, NULL, 0); unzOpenCurrentFile(unzfd); if (!(fd = fopen(FileName, "wb"))) err(1, "fopen %s", FileName); - while ((len = unzReadCurrentFile(unzfd, &buf, 1024))) { + while ((len = unzReadCurrentFile(unzfd, buf, BUF_SIZ))) { fwrite(buf, len, 1, fd); } fclose(fd); unzGoToNextFile(unzfd); } + free(buf); unzClose(unzfd); unlink(DATFILE); return; -- cgit v1.2.3