www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/12/20/08:45:18

From: "A. Jans-Beken" <jansb000 AT wxs DOT nl>
Newsgroups: comp.os.msdos.djgpp
Subject: Allegro: Possible BUG pack_xxx
Date: Sun, 20 Dec 1998 14:44:59 +0100
Organization: World Access
Lines: 61
Message-ID: <367CFF5B.34FEC861@wxs.nl>
NNTP-Posting-Host: vl0103-0.dial.wxs.nl
Mime-Version: 1.0
X-Trace: reader1.wxs.nl 914161164 17948 195.121.18.103 (20 Dec 1998 13:39:24 GMT)
X-Complaints-To: abuse AT wxs DOT nl
NNTP-Posting-Date: 20 Dec 1998 13:39:24 GMT
X-Mailer: Mozilla 4.04 [en] (Win95; I)
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

I think I found a BUG in Allegro (or I do not understand the
documentation).
The problem is with the pack_xxx functions. A complete source that
demonstrates the problem can be found below.

In the documentation it is stated that a packed file can be written with
the "w" and "w!" parameter. The latter does actually no
file-compression, but 'marks' a file (by inserting the magic code "slh."
at the beginning of the file).

When I want to read-back the file I open it with "r" or "r!". I think,
but it not clear from the documentation, that "r!" should be used when a
file is created with "w!".
In the program below I write one integer with the value 128. When I read
it back then I get the value 29548 (hex: 0x736c). This hex value happens
to represent the first two characters from the magic code "sl".

When I replace "w!" and "r!" by "w" and "r" then everything works fine.

My conclusion: It appears that when opening a pack-file with "r!"
allegro does not correctly handle the magic code.

---my source---------------

#include <iostream.h>
#include <fstream.h>
#include <assert.h>
#include <allegro.h>

void save_pack_test() {

   PACKFILE *f;
   f = pack_fopen("test.tst", "w!");
   assert(f != NULL);

   int x = 128;
   pack_mputw(x, f);

   pack_fclose(f);
   }

void load_pack_test() {

   PACKFILE *f;
   f = pack_fopen("test.tst", "r!");
   assert(f != NULL);

   int x;
   x = pack_mgetw(f);
   cout << "Found the value: " << x << "\n";

   pack_fclose(f);
   }

int main () {
   save_pack_test();
   load_pack_test();
   return 0;
   }


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019