~ubuntu-branches/debian/experimental/apt/experimental

« back to all changes in this revision

Viewing changes to apt-pkg/contrib/md5.cc

  • Committer: Bazaar Package Importer
  • Author(s): Michael Vogt
  • Date: 2010-02-18 22:07:23 UTC
  • mfrom: (9.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20100218220723-zb7zdh6fmsmp30tr
Tags: 0.7.26~exp2
fix crash when LANGUAGE is not set

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
   ##################################################################### */
36
36
                                                                        /*}}}*/
37
37
// Include Files                                                        /*{{{*/
38
 
#include <apt-pkg/contrib/md5.h>
39
 
#include <apt-pkg/contrib/strutl.h>
 
38
#include <apt-pkg/md5.h>
 
39
#include <apt-pkg/strutl.h>
 
40
#include <apt-pkg/macros.h>
40
41
 
41
42
#include <string.h>
42
43
#include <unistd.h>
43
44
#include <netinet/in.h>                          // For htonl
44
45
#include <inttypes.h>
45
46
#include <config.h>
46
 
#include <apt-pkg/contrib/system.h>
47
 
 
48
47
                                                                        /*}}}*/
49
48
 
50
49
// byteSwap - Swap bytes in a buffer                                    /*{{{*/
294
293
{
295
294
   unsigned char Buf[64*64];
296
295
   int Res = 0;
297
 
   while (Size != 0)
 
296
   int ToEOF = (Size == 0);
 
297
   while (Size != 0 || ToEOF)
298
298
   {
299
 
      Res = read(Fd,Buf,min(Size,(unsigned long)sizeof(Buf)));
300
 
      if (Res < 0 || (unsigned)Res != min(Size,(unsigned long)sizeof(Buf)))
301
 
         return false;
 
299
      unsigned n = sizeof(Buf);
 
300
      if (!ToEOF) n = min(Size,(unsigned long)n);
 
301
      Res = read(Fd,Buf,n);
 
302
      if (Res < 0 || (!ToEOF && (unsigned) Res != n)) // error, or short read
 
303
         return false;
 
304
      if (ToEOF && Res == 0) // EOF
 
305
         break;
302
306
      Size -= Res;
303
307
      Add(Buf,Res);
304
308
   }