summaryrefslogtreecommitdiffstats
path: root/Source/bindexplib.cxx
diff options
context:
space:
mode:
authorBill Hoffman <bill.hoffman@kitware.com>2015-06-19 20:12:43 (GMT)
committerBrad King <brad.king@kitware.com>2015-07-06 15:11:01 (GMT)
commitde70c922d9c846cf3a6fabfbedd054c02f4b8934 (patch)
tree6bd58fd4f629b5e0e4f4cb5f74a6e07a5d87e98c /Source/bindexplib.cxx
parent8ea69dfef1e81a9811fe8a3d7198580dd21cb48f (diff)
downloadCMake-de70c922d9c846cf3a6fabfbedd054c02f4b8934.zip
CMake-de70c922d9c846cf3a6fabfbedd054c02f4b8934.tar.gz
CMake-de70c922d9c846cf3a6fabfbedd054c02f4b8934.tar.bz2
bindexplib: Teach DumpFile to return errors
This will allow callers to know if it worked.
Diffstat (limited to 'Source/bindexplib.cxx')
-rw-r--r--Source/bindexplib.cxx17
1 files changed, 10 insertions, 7 deletions
diff --git a/Source/bindexplib.cxx b/Source/bindexplib.cxx
index f14d301..4024e2f 100644
--- a/Source/bindexplib.cxx
+++ b/Source/bindexplib.cxx
@@ -296,7 +296,8 @@ DumpObjFile(PIMAGE_FILE_HEADER pImageFileHeader, FILE *fout)
* dumping routine
*----------------------------------------------------------------------
*/
-void
+
+bool
DumpFile(const char* filename, FILE *fout)
{
HANDLE hFile;
@@ -309,15 +310,15 @@ DumpFile(const char* filename, FILE *fout)
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if (hFile == INVALID_HANDLE_VALUE) {
- fprintf(stderr, "Couldn't open file with CreateFile()\n");
- return;
+ fprintf(stderr, "Couldn't open file '%s' with CreateFile()\n", filename);
+ return false;
}
hFileMapping = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL);
if (hFileMapping == 0) {
CloseHandle(hFile);
fprintf(stderr, "Couldn't open file mapping with CreateFileMapping()\n");
- return;
+ return false;
}
lpFileBase = MapViewOfFile(hFileMapping, FILE_MAP_READ, 0, 0, 0);
@@ -325,13 +326,13 @@ DumpFile(const char* filename, FILE *fout)
CloseHandle(hFileMapping);
CloseHandle(hFile);
fprintf(stderr, "Couldn't map view of file with MapViewOfFile()\n");
- return;
+ return false;
}
dosHeader = (PIMAGE_DOS_HEADER)lpFileBase;
if (dosHeader->e_magic == IMAGE_DOS_SIGNATURE) {
fprintf(stderr, "File is an executable. I don't dump those.\n");
- return;
+ return false;
}
/* Does it look like a i386 COFF OBJ file??? */
else if (
@@ -346,9 +347,11 @@ DumpFile(const char* filename, FILE *fout)
*/
DumpObjFile((PIMAGE_FILE_HEADER) lpFileBase, fout);
} else {
- printf("unrecognized file format\n");
+ printf("unrecognized file format in '%s'\n", filename);
+ return false;
}
UnmapViewOfFile(lpFileBase);
CloseHandle(hFileMapping);
CloseHandle(hFile);
+ return true;
}