IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 9872 for trunk/psLib


Ignore:
Timestamp:
Nov 6, 2006, 6:21:05 PM (20 years ago)
Author:
jhoblitt
Message:

fix error checking in psMetadataConfigRead()

File:
1 edited

Legend:

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

    r9868 r9872  
    1010*  @author Eric Van Alst, MHPCC
    1111*
    12 *  @version $Revision: 1.108 $ $Name: not supported by cvs2svn $
    13 *  @date $Date: 2006-11-06 22:31:31 $
     12*  @version $Revision: 1.109 $ $Name: not supported by cvs2svn $
     13*  @date $Date: 2006-11-07 04:21:05 $
    1414*
    1515*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    12321232    int fd = 0;
    12331233    fd = open(filename, O_RDONLY);
    1234     struct stat buf;                    // Results of stat() for file
    1235     if (fd < 0 || fstat(fd, &buf) != 0) {
     1234    if (fd < 0) {
    12361235        // XXX really should return strerror() here
    12371236        psError(PS_ERR_IO, true,
     
    12411240        return NULL;
    12421241    }
    1243     /*  This appears to be unreachable, but moving to check above just to be sure.
     1242
     1243    // Results of stat() for file
     1244    struct stat buf;
    12441245    if (fstat(fd, &buf) != 0) {
    12451246        psError(PS_ERR_IO, true, _("Unable to stat file '%s'.\n"), filename);
     
    12471248        return NULL;
    12481249    }
    1249     */
     1250
    12501251    // psMetadataConfigParse() is going to read the entire file into memory so
    12511252    // we're trying to be nice by allowing the VM to flush the file out of
    1252     // memory if need be.
    1253     // XXX yes, mmap is evil
    1254     void *file = mmap(0, (size_t)buf.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
     1253    // memory if need be.  XXX we're adding 1 to buf.st_size here in case
     1254    // st_size / system page size has a remaineder of zero (in that case this
     1255    // magic trick may not work because there won't be any trailing \0s at the
     1256    // end of the page).
     1257    void *file = mmap(0, (size_t)buf.st_size + 1, PROT_READ, MAP_PRIVATE, fd, 0);
    12551258    if (file == MAP_FAILED) {
    12561259        psError(PS_ERR_IO, true, _("failed to mmap() file %s"), filename);
    1257         /*        if (close(fd) != 0) {
    1258                     // XXX really should return strerror() here
    1259                     psError(PS_ERR_IO, true, _("Failed to close file '%s'."), filename);
    1260                     return NULL;
    1261                 }
    1262         */
    1263         close(fd);
     1260        if (close(fd) != 0) {
     1261            psError(PS_ERR_IO, true, _("Failed to close file '%s'."), filename);
     1262            return NULL;
     1263        }
    12641264        return NULL;
    12651265    }
    12661266
    12671267    md = psMetadataConfigParse(md, nFail, (char *)file, overwrite);
     1268    if (!md) {
     1269        psError(PS_ERR_IO, true, _("failed to parse file '%s'"), filename);
     1270        return NULL;
     1271    }
    12681272
    12691273    if (munmap(file, (size_t)buf.st_size) != 0) {
     
    12731277            // munmap() error
    12741278            psError(PS_ERR_IO, false, _("Failed to close file '%s'."), filename);
     1279            psFree(md);
    12751280            return NULL;
    12761281        }
    12771282    }
    12781283
    1279     /*
    12801284    if (close(fd) != 0) {
    1281         // XXX really should return strerror() here
    12821285        psError(PS_ERR_IO, true, _("Failed to close file '%s'."), filename);
     1286        psFree(md);
    12831287        return NULL;
    12841288    }
    1285     */
    1286     close(fd);
     1289
    12871290    return md;
    12881291}
Note: See TracChangeset for help on using the changeset viewer.