aboutsummaryrefslogtreecommitdiff
path: root/tgeb/ausland.c
diff options
context:
space:
mode:
Diffstat (limited to 'tgeb/ausland.c')
-rw-r--r--tgeb/ausland.c41
1 files changed, 28 insertions, 13 deletions
diff --git a/tgeb/ausland.c b/tgeb/ausland.c
index f7e32a3..0a6deb3 100644
--- a/tgeb/ausland.c
+++ b/tgeb/ausland.c
@@ -18,22 +18,24 @@
#include <stdio.h>
#include <stdlib.h>
#include <err.h>
+#include <string.h>
#include "tgebdat.h"
-static void rhdr_au(struct au *, FILE *); /* read header */
-static void rent_au(struct au *, FILE *); /* read entries */
+static void rhdr_au(AU *, FILE *); /* read header */
+static void rent_au(AU *, FILE *); /* read entries */
-struct au *
+AU *
tgeb_read_au(char *file)
{
- struct au *au;
+ AU *au;
FILE *fd;
if (!(fd = fopen(file, "r")))
err(1, "fopen %s", file);
- if (!(au = (struct au *) malloc(sizeof(struct au))))
+ if (!(au = malloc(sizeof(AU))))
err(1, "malloc");
+ bzero(au, sizeof(AU));
rhdr_au(au, fd);
rent_au(au, fd);
@@ -43,7 +45,7 @@ tgeb_read_au(char *file)
}
void
-rhdr_au(struct au * au, FILE * fd)
+rhdr_au(AU * au, FILE * fd)
{
fread(&au->l, sizeof(au->l), 1, fd);
fread(&au->q, sizeof(au->q), 1, fd);
@@ -51,21 +53,18 @@ rhdr_au(struct au * au, FILE * fd)
}
void
-rent_au(struct au * au, FILE * fd)
+rent_au(AU * au, FILE * fd)
{
int i, j;
- if (!(au->d = (struct au_d *)
- calloc(au->l, sizeof(struct au_d))))
+ if (!(au->d = calloc(au->l, sizeof(AU_D))))
err(1, "malloc");
- if (!(au->max = (unsigned short *)
- calloc(au->q, sizeof(unsigned short))))
+ if (!(au->max = calloc(au->q, sizeof(unsigned short))))
err(1, "malloc");
fseek(fd, 4, SEEK_SET);
for (i = 0; i < au->l; i++) {
- au->d[i].id = (unsigned short *)
- calloc(au->q, sizeof(unsigned short));
+ au->d[i].id = calloc(au->q, sizeof(unsigned short));
for (j = 0; j < au->q; j++) {
fread(&au->d[i].id[j], sizeof(au->d[i].id[j]), 1, fd);
if (au->d[i].id[j] > au->max[j])
@@ -79,3 +78,19 @@ rent_au(struct au * au, FILE * fd)
}
return;
}
+
+void
+tgeb_free_au(AU * au)
+{
+ int i;
+
+ for (i = 0; i < au->l; i++) {
+ free(au->d[i].id);
+ free(au->d[i].land);
+ free(au->d[i].dial);
+ }
+ free(au->d);
+ free(au->max);
+ free(au);
+ return;
+}