IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 15505


Ignore:
Timestamp:
Nov 7, 2007, 6:24:01 PM (19 years ago)
Author:
Paul Price
Message:

Remove mmap code --- should not have done this in the first place.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/types/psMetadataConfig.c

    r15411 r15505  
    1111*  @author Joshua Hoblitt, University of Hawaii 2006-2007
    1212*
    13 *  @version $Revision: 1.141 $ $Name: not supported by cvs2svn $
    14 *  @date $Date: 2007-10-29 21:36:02 $
     13*  @version $Revision: 1.142 $ $Name: not supported by cvs2svn $
     14*  @date $Date: 2007-11-08 04:24:01 $
    1515*
    1616*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    2626#include <limits.h>
    2727#include <strings.h>
    28 #ifdef USE_MMAP_TO_READ_FILE
    29 #include <sys/mman.h>
    30 #include <sys/stat.h>
    31 #include <fcntl.h>
    32 #include <unistd.h>
    33 #else
    3428#include "psSlurp.h"
    35 #endif
    3629
    3730#include "psMemory.h"
     
    11811174    PS_ASSERT_STRING_NON_EMPTY(filename, NULL);
    11821175
    1183 #ifdef USE_MMAP_TO_READ_FILE
    1184     // Attempt to open specified file
    1185     int fd = 0;
    1186     fd = open(filename, O_RDONLY);
    1187     if (fd < 0) {
    1188         // XXX really should return strerror() here
    1189         psError(PS_ERR_IO, true,
    1190                 _("Failed to open file '%s'. Check if it exists and it has the proper "
    1191                   "permissions."), filename);
    1192         close(fd);
    1193         return NULL;
    1194     }
    1195 
    1196     // Results of stat() for file
    1197     struct stat buf;
    1198     if (fstat(fd, &buf) != 0) {
    1199         psError(PS_ERR_IO, true, _("Unable to stat file '%s'.\n"), filename);
    1200         close(fd);
    1201         return NULL;
    1202     }
    1203     // XXX EAM : for some reason, the mmap below results in a buffer which causes
    1204     // bus errors if the file is empty.  This seems like a strange result...
    1205     if (buf.st_size == 0) {
    1206         // We successfully read everything we could.  Return a MD containing what we read.
    1207         close(fd);
    1208         return psMetadataAlloc();
    1209     }
    1210 
    1211     // psMetadataConfigParse() is going to read the entire file into memory so
    1212     // lets use mmap() to allow the system to be cleverer about what gets read
    1213     //
    1214     // We're adding 1 to buf.st_size here in case st_size / system page size has
    1215     // a remainder of zero (otherwise there won't be any trailing \0s at the end
    1216     // of the page).
    1217     int nBytes = buf.st_size + 1;
    1218 
    1219     void *file = mmap(0, nBytes, PROT_READ, MAP_PRIVATE, fd, 0);
    1220     if (file == MAP_FAILED) {
    1221         psError(PS_ERR_IO, true, _("failed to mmap() file %s"), filename);
    1222         if (close(fd) != 0) {
    1223             psError(PS_ERR_IO, true, _("Failed to close file '%s'."), filename);
    1224         }
    1225         return NULL;
    1226     }
    1227 #else
    12281176    psString file = psSlurpFilename(filename);
    1229 #endif
    12301177
    12311178    md = psMetadataConfigParse(md, nFail, (char *)file, overwrite);
     
    12361183    }
    12371184
    1238 #ifdef USE_MMAP_TO_READ_FILE
    1239     if (munmap(file, nBytes) != 0) {
    1240         psError(PS_ERR_IO, true, _("failed to munmap file '%s'"), filename);
    1241         psFree(md);
    1242         return false;
    1243     }
    1244 
    1245     if (close(fd) != 0) {
    1246         psError(PS_ERR_IO, true, _("Failed to close file '%s'."), filename);
    1247         psFree(md);
    1248         return false;
    1249     }
    1250 #else
    12511185    psFree(file);
    1252 #endif
    12531186
    12541187    return md;
Note: See TracChangeset for help on using the changeset viewer.