diff options
Diffstat (limited to 'generic')
-rw-r--r-- | generic/MapInfo.c | 63 |
1 files changed, 34 insertions, 29 deletions
diff --git a/generic/MapInfo.c b/generic/MapInfo.c index f050898..c843c48 100644 --- a/generic/MapInfo.c +++ b/generic/MapInfo.c @@ -27,8 +27,6 @@ */ -#include <stdlib.h> -#include <stdio.h> #ifndef _WIN32 #include <sys/param.h> #include <netinet/in.h> @@ -1185,20 +1183,20 @@ FillMap(ZnMapInfoId map, VideoMap *vm) */ static int ZnMapInfoGetVideomap(ZnMapInfoId map, - char *filename, - unsigned int index) + char *filename, + unsigned int index) { VideoMap current_vm; - FILE *file; + Tcl_Channel chan; unsigned int cur_index, cur_id; /* Open the specified map file. */ -#ifdef _WIN32 - file = fopen(filename, "rb"); -#else - file = fopen(filename, "r"); -#endif - if (file == NULL) { + chan = Tcl_OpenFileChannel(NULL, filename, "r", 0); + if (chan == NULL) { + return TCL_ERROR; + } + if (Tcl_SetChannelOption(NULL, chan, + "-translation", "binary") == TCL_ERROR) { return TCL_ERROR; } @@ -1206,12 +1204,14 @@ ZnMapInfoGetVideomap(ZnMapInfoId map, /* First skip the leading maps up to index. */ cur_index = 0; - if (fread(¤t_vm, sizeof(VideoMap), 1, file) != 1) { + if (Tcl_Read(chan, (char *) ¤t_vm, + sizeof(VideoMap)) != sizeof(VideoMap)) { goto error; } cur_id = ntohi((unsigned int) current_vm.id); while (cur_index != index) { - if (fread(¤t_vm, sizeof(VideoMap), 1, file) != 1) { + if (Tcl_Read(chan, (char *) ¤t_vm, + sizeof(VideoMap)) != sizeof(VideoMap)) { goto error; } if (cur_id != ntohi((unsigned int) current_vm.id)) { @@ -1224,17 +1224,20 @@ ZnMapInfoGetVideomap(ZnMapInfoId map, do { ReorderVidomap(¤t_vm); FillMap(map, ¤t_vm); - if ((fread(¤t_vm, sizeof(VideoMap), 1, file) != 1) && !feof(file)) { + if ((Tcl_Read(chan, (char *) ¤t_vm, + sizeof(VideoMap)) != sizeof(VideoMap)) && + !Tcl_Eof(chan)) { goto error; } } - while ((cur_id == ntohi((unsigned int) current_vm.id)) && !feof(file)); + while ((cur_id == ntohi((unsigned int) current_vm.id)) && + !Tcl_Eof(chan)); - fclose(file); + Tcl_Close(NULL, chan); return TCL_OK; error: - fclose(file); + Tcl_Close(NULL, chan); return TCL_ERROR; } @@ -1252,24 +1255,25 @@ ZnMapInfoGetVideomap(ZnMapInfoId map, static ZnList ZnMapInfoVideomapIds(char *filename) { - FILE *file; + Tcl_Channel chan; VideoMap current_vm; unsigned int cur_id; ZnList ids; /* Open the specified map file. */ -#ifdef _WIN32 - file = fopen(filename, "rb"); -#else - file = fopen(filename, "r"); -#endif - if (file == NULL) { + chan = Tcl_OpenFileChannel(NULL, filename, "r", 0); + if (chan == NULL) { + return NULL; + } + if (Tcl_SetChannelOption(NULL, chan, + "-translation", "binary") == TCL_ERROR) { return NULL; } - if (fread(¤t_vm, sizeof(VideoMap), 1, file) != 1) { + if (Tcl_Read(chan, (char *) ¤t_vm, + sizeof(VideoMap)) != sizeof(VideoMap)) { error: - fclose(file); + Tcl_Close(NULL, chan); return NULL; } cur_id = ntohi((unsigned int) current_vm.id); @@ -1278,7 +1282,8 @@ ZnMapInfoVideomapIds(char *filename) ZnListAdd(ids, &cur_id, ZnListTail); do { - if (fread(¤t_vm, sizeof(VideoMap), 1, file) != 1) { + if (Tcl_Read(chan, (char *) ¤t_vm, + sizeof(VideoMap)) != sizeof(VideoMap)) { ZnListFree(ids); goto error; } @@ -1288,9 +1293,9 @@ ZnMapInfoVideomapIds(char *filename) ZnListAdd(ids, &cur_id, ZnListTail); } } - while (!feof(file)); + while (!Tcl_Eof(chan)); - fclose(file); + Tcl_Close(NULL, chan); return ids; } |