~mvo/apt/mvo

« back to all changes in this revision

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

  • Committer: Arch Librarian
  • Date: 2004-09-20 16:56:32 UTC
  • Revision ID: Arch-1:apt@arch.ubuntu.com%apt--MAIN--0--patch-614
Join with aliencode
Author: jgg
Date: 2001-02-20 07:03:16 GMT
Join with aliencode

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
// -*- mode: cpp; mode: fold -*-
2
2
// Description                                                          /*{{{*/
3
 
// $Id: mmap.cc,v 1.20 1999/10/02 04:14:54 jgg Exp $
 
3
// $Id: mmap.cc,v 1.21 2001/02/20 07:03:17 jgg Exp $
4
4
/* ######################################################################
5
5
   
6
6
   MMap Class - Provides 'real' mmap or a faked mmap using read().
29
29
#include <apt-pkg/mmap.h>
30
30
#include <apt-pkg/error.h>
31
31
 
 
32
#include <apti18n.h>
 
33
 
32
34
#include <sys/mman.h>
33
35
#include <sys/stat.h>
34
36
#include <unistd.h>
77
79
      Map = MAP_PRIVATE;
78
80
   
79
81
   if (iSize == 0)
80
 
      return _error->Error("Can't mmap an empty file");
 
82
      return _error->Error(_("Can't mmap an empty file"));
81
83
   
82
84
   // Map it.
83
85
   Base = mmap(0,iSize,Prot,Map,Fd.Fd(),0);
84
86
   if (Base == (void *)-1)
85
 
      return _error->Errno("mmap","Couldn't make mmap of %u bytes",iSize);
 
87
      return _error->Errno("mmap",_("Couldn't make mmap of %lu bytes"),iSize);
86
88
 
87
89
   return true;
88
90
}
102
104
      _error->Warning("Unable to munmap");
103
105
   
104
106
   iSize = 0;
 
107
   Base = 0;
105
108
   return true;
106
109
}
107
110
                                                                        /*}}}*/
150
153
      return;
151
154
   
152
155
   unsigned long EndOfFile = Fd->Size();
153
 
   Fd->Seek(WorkSpace);
154
 
   char C = 0;
155
 
   Fd->Write(&C,sizeof(C));
 
156
   if (EndOfFile > WorkSpace)
 
157
      WorkSpace = EndOfFile;
 
158
   else
 
159
   {
 
160
      Fd->Seek(WorkSpace);
 
161
      char C = 0;
 
162
      Fd->Write(&C,sizeof(C));
 
163
   }
 
164
   
156
165
   Map(F);
157
166
   iSize = EndOfFile;
158
167
}
182
191
   }
183
192
   
184
193
   unsigned long EndOfFile = iSize;
185
 
   Sync();
186
194
   iSize = WorkSpace;
187
195
   Close(false);
188
196
   ftruncate(Fd->Fd(),EndOfFile);
189
 
   Fd->Close();
190
197
}  
191
198
                                                                        /*}}}*/
192
199
// DynamicMMap::RawAllocate - Allocate a raw chunk of unaligned space   /*{{{*/