|
Bug in allegro filestytem? I think that reads are drifting! |
nshade
Member #4,372
February 2004
|
I think I have a test case here. When reading in data from a file, allegro is randomly pushing the read index ahead one. Here is the output from reading a zip file with no compression. Quote:
Got Header Pay close attention to the first and last reads.. Quote:
------ ------ It seems to be screwing up doing a read after an al_fseek() Here is my example code. To test yourself, use a zip file named default.zip with a few uncompressed files inside. ==EDIT== Windows 10 x64 BTW 1#include <stdio.h>
2#include <allegro5/allegro.h>
3#include <allegro5/allegro_primitives.h>
4#include <allegro5/allegro_image.h>
5#include <allegro5/allegro_video.h>
6#include <allegro5/allegro_font.h>
7#include <allegro5/allegro_ttf.h>
8
9ALLEGRO_DISPLAY *d;
10ALLEGRO_FILE *zip;
11ALLEGRO_FILE *target;
12
13
14void startup()
15{
16 if (!al_init()) {
17 fprintf(stderr, "failed to initialize allegro!\n");
18 exit(1);
19 }
20 if (!al_install_keyboard()) {
21 fprintf(stderr, "Error installing keyboard.\n");
22 exit(1);
23 }
24
25 if (!al_init_primitives_addon()) {
26 fprintf(stderr, "Error installing prims.\n");
27 exit(1);
28 }
29
30 if (!al_init_image_addon()) {
31 fprintf(stderr, "Error installing image addon.\n");
32 exit(1);
33 }
34
35
36 if (!al_init_font_addon()) {
37 fprintf(stderr, "Error installing font addon.\n");
38 exit(1);
39 }
40
41 if (!al_init_ttf_addon()) {
42 fprintf(stderr, "Error installing TTF addon.\n");
43 exit(1);
44 }
45
46
47 d = al_create_display(1024, 768);
48 al_clear_to_color(al_map_rgb(0, 0, 0));
49
50
51}
52
53
54int main(int argc, char **argv)
55{
56 int header;
57 int filesize;
58 int namesize;
59 char filename[255];
60
61
62 startup();
63 zip=al_fopen("default.zip", "r");
64 while (!al_feof(zip)) {
65
66
67 header = al_fread32le(zip);
68 if (header == 0x04034b50) { printf("Got Header\n"); }
69 else { printf("NO HEADER!\n"); exit(1); }
70 printf("Read in 4 bytes After header, now at %d\n", al_ftell(zip));
71 al_fseek(zip, 18, ALLEGRO_SEEK_CUR);
72 printf("Skipped ahead 18 bytes , now at %d\n", al_ftell(zip));
73 filesize = al_fread32le(zip);
74 printf("Read in 4 bytes for filesize - now at %d\n", al_ftell(zip));
75 printf("Filesize=%d\n", filesize);
76 namesize = al_fread16le(zip);
77 printf("Read in two bytes namesize - now at %d\n", al_ftell(zip));
78 printf("Namesize=%d\n", namesize);
79 printf("Still at %d skipping 2 bytes\n", al_ftell(zip));
80 al_fread16le(zip); //skip 2
81 printf("skpped 2 bytes Now at filename %d\n", al_ftell(zip));
82 al_fread(zip, filename, namesize);
83 printf("filename read in %d bytes , Now at %d\n",namesize, al_ftell(zip));
84 filename[namesize] = '\0';
85 printf("adjusted filename should still be at %d\n", al_ftell(zip));
86 printf("Filename=%s\n", filename);
87 printf("skipping ahead %d bytes\n", filesize);
88 al_fseek(zip, filesize, ALLEGRO_SEEK_CUR);
89 printf("Skipped File! Now at %d\n", al_ftell(zip));
90 }
91
92
93 while (1);
|
nshade
Member #4,372
February 2004
|
HEADDESK Man, Windows! Why do you make me want to hurt you? |
Audric
Member #907
January 2001
|
Actually it's libc's choice that unless you open files with "b" flag, the mode is "text" (And MS-DOS choice of line ending) |
Edgar Reynaldo
Major Reynaldo
May 2007
|
That's pretty much the first thing you learn when doing io. Binary or text mode. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
|