Changeset 9872 for trunk/psLib
- Timestamp:
- Nov 6, 2006, 6:21:05 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/types/psMetadataConfig.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/types/psMetadataConfig.c
r9868 r9872 10 10 * @author Eric Van Alst, MHPCC 11 11 * 12 * @version $Revision: 1.10 8$ $Name: not supported by cvs2svn $13 * @date $Date: 2006-11-0 6 22:31:31$12 * @version $Revision: 1.109 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2006-11-07 04:21:05 $ 14 14 * 15 15 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 1232 1232 int fd = 0; 1233 1233 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) { 1236 1235 // XXX really should return strerror() here 1237 1236 psError(PS_ERR_IO, true, … … 1241 1240 return NULL; 1242 1241 } 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; 1244 1245 if (fstat(fd, &buf) != 0) { 1245 1246 psError(PS_ERR_IO, true, _("Unable to stat file '%s'.\n"), filename); … … 1247 1248 return NULL; 1248 1249 } 1249 */ 1250 1250 1251 // psMetadataConfigParse() is going to read the entire file into memory so 1251 1252 // 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); 1255 1258 if (file == MAP_FAILED) { 1256 1259 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 } 1264 1264 return NULL; 1265 1265 } 1266 1266 1267 1267 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 } 1268 1272 1269 1273 if (munmap(file, (size_t)buf.st_size) != 0) { … … 1273 1277 // munmap() error 1274 1278 psError(PS_ERR_IO, false, _("Failed to close file '%s'."), filename); 1279 psFree(md); 1275 1280 return NULL; 1276 1281 } 1277 1282 } 1278 1283 1279 /*1280 1284 if (close(fd) != 0) { 1281 // XXX really should return strerror() here1282 1285 psError(PS_ERR_IO, true, _("Failed to close file '%s'."), filename); 1286 psFree(md); 1283 1287 return NULL; 1284 1288 } 1285 */ 1286 close(fd); 1289 1287 1290 return md; 1288 1291 }
Note:
See TracChangeset
for help on using the changeset viewer.
