Index: src/mgr/filemgr.cpp =================================================================== --- src/mgr/filemgr.cpp (revision 2419) +++ src/mgr/filemgr.cpp (working copy) @@ -273,8 +273,7 @@ file->seek(0, SEEK_SET); while (size > 0) { bytes = file->read(nibble, 32767); - write(fd, nibble, (bytes < size)?bytes:size); - size -= bytes; + size -= write(fd, nibble, (bytes < size)?bytes:size); } // zero out the file ::close(file->fd); @@ -396,7 +395,7 @@ int FileMgr::copyFile(const char *sourceFile, const char *targetFile) { - int sfd, dfd, len; + int sfd, dfd, len, written; char buf[4096]; if ((sfd = ::open(sourceFile, O_RDONLY|O_BINARY, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH)) < 1) @@ -406,7 +405,7 @@ do { len = read(sfd, buf, 4096); - write(dfd, buf, len); + written = write(dfd, buf, len); } while(len == 4096); ::close(dfd); Index: src/utilfuns/zlib/untgz.c =================================================================== --- src/utilfuns/zlib/untgz.c (revision 2419) +++ src/utilfuns/zlib/untgz.c (working copy) @@ -13,6 +13,8 @@ #include #ifdef unix # include +# include +# include #else # include # include @@ -80,7 +82,7 @@ enum { TGZ_EXTRACT = 0, TGZ_LIST }; -static char *TGZfname OF((const char *)); +// static char *TGZfname OF((const char *)); void TGZnotfound OF((const char *)); int getoct OF((char *, int)); @@ -105,23 +107,24 @@ /* Return the real name of the TGZ archive */ /* or NULL if it does not exist. */ -static char *TGZfname OF((const char *fname)) -{ - static char buffer[1024]; - int origlen,i; - - strcpy(buffer,fname); - origlen = strlen(buffer); +// COMMENTED OUT 20090516 for SWORD +// static char *TGZfname OF((const char *fname)) +// { +// static char buffer[1024]; +// int origlen,i; +// +// strcpy(buffer,fname); +// origlen = strlen(buffer); +// +// for (i=0; TGZprefix[i]; i++) +// { +// strcpy(buffer+origlen,TGZprefix[i]); +// if (access(buffer,F_OK) == 0) +// return buffer; +// } +// return NULL; +// } - for (i=0; TGZprefix[i]; i++) - { - strcpy(buffer+origlen,TGZprefix[i]); - if (access(buffer,F_OK) == 0) - return buffer; - } - return NULL; -} - /* error message for the filename */ void TGZnotfound OF((const char *fname)) Index: tests/testblocks.cpp =================================================================== --- tests/testblocks.cpp (revision 2419) +++ tests/testblocks.cpp (working copy) @@ -29,14 +29,18 @@ void addEntry(EntriesBlock *eb) { string input; string body; - char line[1024]; + char line[1024], *c; std::cout << "\nEnter new Entry's text. '.' on an empty line to finish:\n"; do { std::cout << "> "; - fgets(line, 1000, stdin); - input = line; - if (input.compare(".")) - body.append(input); + c = fgets(line, 1000, stdin); + if (c == NULL) { + std::cerr <<"ERROR: fgets failed during addEntry\n"; + } else { + input = line; + if (input.compare(".")) + body.append(input); + } } while (input.compare(".")); std::cout << "Adding new entry. Index is: " << eb->addEntry(body.c_str()) << "\n\n"; @@ -72,29 +76,33 @@ EntriesBlock *eb = new EntriesBlock(); string input; - char line[1024]; + char line[1024], *c; std::cout << "Initial entry count should be 0: " << eb->getCount() << "\n"; do { std::cout << "[" << eb->getCount() << "] > "; - fgets(line, 1000, stdin); - input = line; - if (input.length() > 0) { - switch (input[0]) { - case 'a': addEntry(eb); break; - case 'p': printEntry(eb, atoi(input.c_str()+1)); break; - case 'r': removeEntry(eb, atoi(input.c_str()+1)); break; - case 's': printSize(eb); break; - case 'q': break; - case '?': - default: - std::cout << "\n a - add a new entry\n"; - std::cout << " p - print entry\n"; - std::cout << " r - remove entry\n"; - std::cout << " s - print size of raw data\n"; - std::cout << " q - quit\n\n"; - break; + c = fgets(line, 1000, stdin); + if (c == NULL) { + std::cerr << "ERROR: fgets failed in main\n"; + } else { + input = line; + if (input.length() > 0) { + switch (input[0]) { + case 'a': addEntry(eb); break; + case 'p': printEntry(eb, atoi(input.c_str()+1)); break; + case 'r': removeEntry(eb, atoi(input.c_str()+1)); break; + case 's': printSize(eb); break; + case 'q': break; + case '?': + default: + std::cout << "\n a - add a new entry\n"; + std::cout << " p - print entry\n"; + std::cout << " r - remove entry\n"; + std::cout << " s - print size of raw data\n"; + std::cout << " q - quit\n\n"; + break; + } } } } Index: tests/rawldidxtest.cpp =================================================================== --- tests/rawldidxtest.cpp (revision 2419) +++ tests/rawldidxtest.cpp (working copy) @@ -19,6 +19,7 @@ #include #include #include +#include #ifndef __GNUC__ #include Index: tests/parsekey.cpp =================================================================== --- tests/parsekey.cpp (revision 2419) +++ tests/parsekey.cpp (working copy) @@ -16,6 +16,7 @@ */ #include +#include #include #include Index: tests/localetest.cpp =================================================================== --- tests/localetest.cpp (revision 2419) +++ tests/localetest.cpp (working copy) @@ -18,6 +18,7 @@ #include #include #include +#include #ifndef NO_SWORD_NAMESPACE using namespace sword; #endif Index: tests/filtertest.cpp =================================================================== --- tests/filtertest.cpp (revision 2419) +++ tests/filtertest.cpp (working copy) @@ -20,6 +20,7 @@ #include #include #include +#include //#include #ifndef NO_SWORD_NAMESPACE using namespace sword; Index: utilities/stepdump.cpp =================================================================== --- utilities/stepdump.cpp (revision 2419) +++ utilities/stepdump.cpp (working copy) @@ -151,33 +151,56 @@ void readVersion(int fd, Version *versionRecord) { + int r; cout << "\n\nReading Version Record (" << 16/*sizeof(struct Version)*/ << " bytes)\n\n"; // DO NOT USE BECAUSE OF RECORD BYTE ALIGNMENT PROBLEMS // read(fd, &versionRecord, sizeof(struct Version)); cout << "Version Record Information\n"; - read(fd, &(versionRecord->versionRecordSize), 2); + r = read(fd, &(versionRecord->versionRecordSize), 2); + if (r != 2) + perror("ERROR: read failed in readVersion"); cout << "\tversionRecordSize: " << versionRecord->versionRecordSize << "\n"; - read(fd, &(versionRecord->publisherID), 2); + r = read(fd, &(versionRecord->publisherID), 2); + if (r != 2) + perror("ERROR: read failed in readVersion"); cout << "\tpublisherID: " << versionRecord->publisherID << "\n"; - read(fd, &(versionRecord->bookID), 2); + r = read(fd, &(versionRecord->bookID), 2); + if (r != 2) + perror("ERROR: read failed in readVersion"); cout << "\tbookID: " << versionRecord->bookID << "\n"; - read(fd, &(versionRecord->setID), 2); + r = read(fd, &(versionRecord->setID), 2); + if (r != 2) + perror("ERROR: read failed in readVersion"); cout << "\tsetID: " << versionRecord->setID << "\n"; - read(fd, &(versionRecord->conversionProgramVerMajor), 1); + r = read(fd, &(versionRecord->conversionProgramVerMajor), 1); + if (r != 1) + perror("ERROR: read failed in readVersion"); cout << "\tconversionProgramVerMajor: " << (int)versionRecord->conversionProgramVerMajor << "\n"; - read(fd, &(versionRecord->conversionProgramVerMinor), 1); + r = read(fd, &(versionRecord->conversionProgramVerMinor), 1); + if (r != 1) + perror("ERROR: read failed in readVersion"); cout << "\tconversionProgramVerMinor: " << (int)versionRecord->conversionProgramVerMinor << "\n"; - read(fd, &(versionRecord->leastCompatSTEPVerMajor), 1); + r = read(fd, &(versionRecord->leastCompatSTEPVerMajor), 1); + if (r != 1) + perror("ERROR: read failed in readVersion"); cout << "\tleastCompatSTEPVerMajor: " << (int)versionRecord->leastCompatSTEPVerMajor << "\n"; - read(fd, &(versionRecord->leastCompatSTEPVerMinor), 1); + r = read(fd, &(versionRecord->leastCompatSTEPVerMinor), 1); + if (r != 1) + perror("ERROR: read failed in readVersion"); cout << "\tleastCompatSTEPVerMinor: " << (int)versionRecord->leastCompatSTEPVerMinor << "\n"; - read(fd, &(versionRecord->encryptionType), 1); + r = read(fd, &(versionRecord->encryptionType), 1); + if (r != 1) + perror("ERROR: read failed in readVersion"); cout << "\tencryptionType: " << (int)versionRecord->encryptionType << "\n"; - read(fd, &(versionRecord->editionID), 1); + r = read(fd, &(versionRecord->editionID), 1); + if (r != 1) + perror("ERROR: read failed in readVersion"); cout << "\teditionID: " << (int)versionRecord->editionID << "\n"; - read(fd, &(versionRecord->modifiedBy), 2); + r = read(fd, &(versionRecord->modifiedBy), 2); + if (r != 2) + perror("ERROR: read failed in readVersion"); cout << "\tmodifiedBy: " << versionRecord->modifiedBy << "\n"; int skip = versionRecord->versionRecordSize - 16/*sizeof(struct Version*/; @@ -185,33 +208,49 @@ if (skip) { cout << "\nSkipping " << skip << " unknown bytes.\n"; char *skipbuf = new char[skip]; - read(fd, skipbuf, skip); + r = read(fd, skipbuf, skip); + if (r != skip) + perror("ERROR: read failed in readVersion"); delete [] skipbuf; } } void readViewableHeader(int fd, ViewableHeader *viewableHeaderRecord) { - + int r; cout << "\n\nReading Viewable Header Record (" << 16/*sizeof(struct ViewableHeader)*/ << " bytes)\n\n"; // DO NOT USE BECAUSE OF RECORD BYTE ALIGNMENT PROBLEMS // read(fd, &viewableHeaderRecord, sizeof(struct ViewableHeader)); cout << "Viewable Header Record Information\n"; - read(fd, &(viewableHeaderRecord->viewableHeaderRecordSize), 2); + r = read(fd, &(viewableHeaderRecord->viewableHeaderRecordSize), 2); + if (r != 2) + perror("ERROR: read failed in readViewableHeader"); cout << "\tviewableHeaderRecordSize: " << viewableHeaderRecord->viewableHeaderRecordSize << "\n"; - read(fd, &(viewableHeaderRecord->viewableBlocksCount), 4); + r = read(fd, &(viewableHeaderRecord->viewableBlocksCount), 4); + if (r != 4) + perror("ERROR: read failed in readViewableHeader"); cout << "\tviewableBlocksCount: " << viewableHeaderRecord->viewableBlocksCount << "\n"; - read(fd, &(viewableHeaderRecord->glossBlocksCount), 4); + r = read(fd, &(viewableHeaderRecord->glossBlocksCount), 4); + if (r != 4) + perror("ERROR: read failed in readViewableHeader"); cout << "\tglossBlocksCount: " << viewableHeaderRecord->glossBlocksCount << "\n"; - read(fd, &(viewableHeaderRecord->compressionType), 1); + r = read(fd, &(viewableHeaderRecord->compressionType), 1); + if (r != 1) + perror("ERROR: read failed in readViewableHeader"); cout << "\tcompressionType: " << (int)viewableHeaderRecord->compressionType << "(0 - none; 1 - LZSS)\n"; - read(fd, &(viewableHeaderRecord->reserved1), 1); + r = read(fd, &(viewableHeaderRecord->reserved1), 1); + if (r != 1) + perror("ERROR: read failed in readViewableHeader"); cout << "\treserved1: " << (int)viewableHeaderRecord->reserved1 << "\n"; - read(fd, &(viewableHeaderRecord->blockEntriesSize), 2); + r = read(fd, &(viewableHeaderRecord->blockEntriesSize), 2); + if (r != 2) + perror("ERROR: read failed in readViewableHeader"); cout << "\tblockEntriesSize: " << viewableHeaderRecord->blockEntriesSize << "\n"; - read(fd, &(viewableHeaderRecord->reserved2), 2); + r = read(fd, &(viewableHeaderRecord->reserved2), 2); + if (r != 2) + perror("ERROR: read failed in readViewableHeader"); cout << "\treserved2: " << viewableHeaderRecord->reserved2 << "\n"; int skip = viewableHeaderRecord->viewableHeaderRecordSize - 16/*sizeof(struct ViewableHeader)*/; @@ -219,18 +258,23 @@ if (skip) { cout << "\nSkipping " << skip << " unknown bytes.\n"; char *skipbuf = new char[skip]; - read(fd, skipbuf, skip); + r = read(fd, skipbuf, skip); + if (r != skip) + perror("ERROR: read failed in readViewableHeader"); delete [] skipbuf; } } void readViewableBlockText(int fd, ViewableBlock *vb, char **buf) { + int r; unsigned long size = vb->size; *buf = new char [ ((vb->size > vb->uncompressedSize) ? vb->size : vb->uncompressedSize) + 1 ]; lseek(fd, vb->offset, SEEK_SET); - read(fd, *buf, vb->size); + r = read(fd, *buf, vb->size); + if (r != vb->size) + perror("ERROR: read failed in readViewableBlocktext"); compress->zBuf(&size, *buf); strcpy(*buf, compress->Buf()); @@ -240,30 +284,41 @@ void readViewableBlock(int fd, ViewableBlock *vb) { - + int r; cout << "\n\nReading Viewable Block (" << 12/*sizeof(struct ViewableHeader)*/ << " bytes)\n\n"; // DO NOT USE BECAUSE OF RECORD BYTE ALIGNMENT PROBLEMS // read(fd, &vb, sizeof(struct ViewableBlock)); cout << "Viewable Block Information\n"; - read(fd, &(vb->offset), 4); + r = read(fd, &(vb->offset), 4); + if (r != 4) + perror("ERROR: read failed in readViewableBlock"); cout << "\toffset: " << vb->offset << "\n"; - read(fd, &(vb->uncompressedSize), 4); + r = read(fd, &(vb->uncompressedSize), 4); + if (r != 4) + perror("ERROR: read failed in readViewableBlock"); cout << "\tuncompressedSize: " << vb->uncompressedSize << "\n"; - read(fd, &(vb->size), 4); + r = read(fd, &(vb->size), 4); + if (r != 4) + perror("ERROR: read failed in readViewableBlock"); cout << "\tsize: " << vb->size << "\n"; } void readHeaderControlWordAreaText(int fd, char **buf) { + int r; long headerControlWordAreaSize; - read(fd, &headerControlWordAreaSize, 4); + r = read(fd, &headerControlWordAreaSize, 4); + if (r != 4) + perror("ERROR: read failed in readHeaderControlWordAreaText"); cout << "Reading Header Control Word Area (" << headerControlWordAreaSize << " bytes)\n\n"; *buf = new char [headerControlWordAreaSize + 1]; - read(fd, *buf, headerControlWordAreaSize); + r = read(fd, *buf, headerControlWordAreaSize); + if (r != headerControlWordAreaSize) + perror("ERROR: read failed in readHeaderControlWordAreaText"); (*buf)[headerControlWordAreaSize] = 0; cout << "headerControlWordArea:\n" << *buf << "\n"; Index: utilities/treeidxutil.cpp =================================================================== --- utilities/treeidxutil.cpp (revision 2419) +++ utilities/treeidxutil.cpp (working copy) @@ -49,27 +49,33 @@ void setLocalName(TreeKeyIdx *treeKey) { - char buf[1023]; + char buf[1023], *c; std::cout << "Enter New Node Name: "; - fgets(buf, 1000, stdin); + c = fgets(buf, 1000, stdin); + if (c == NULL) + std::cerr << "ERROR: fgets failed in setLocalName\n"; treeKey->setLocalName(buf); treeKey->save(); } void assurePath(TreeKeyIdx *treeKey) { - char buf[1023]; + char buf[1023], *c; std::cout << "Enter path: "; - fgets(buf, 1000, stdin); + c = fgets(buf, 1000, stdin); + if (c == NULL) + std::cerr << "ERROR: fgets failed in assurePath\n"; treeKey->assureKeyPath(buf); } void appendSibbling(TreeKeyIdx *treeKey) { if (treeKey->getOffset()) { - char buf[1023]; + char buf[1023], *c; std::cout << "Enter New Sibbling Name: "; - fgets(buf, 1000, stdin); + c = fgets(buf, 1000, stdin); + if (c == NULL) + std::cerr < "ERROR: fgets failed in appendSibbling\n"; treeKey->append(); treeKey->setLocalName(buf); treeKey->save(); @@ -79,9 +85,11 @@ void appendChild(TreeKeyIdx *treeKey) { - char buf[1023]; + char buf[1023], *c; std::cout << "Enter New Child Name: "; - fgets(buf, 1000, stdin); + c = fgets(buf, 1000, stdin); + if (c == NULL) + std::cerr << "ERROR: fgets failed in appendChild\n"; treeKey->appendChild(); treeKey->setLocalName(buf); treeKey->save(); @@ -114,11 +122,13 @@ TreeKeyIdx root = *treeKey; std::string input; - char line[1024]; + char line[1024], *c; do { std::cout << "[" << treeKey->getText() << "] > "; - fgets(line, 1000, stdin); + c = fgets(line, 1000, stdin); + if (c == NULL) + std::cerr << "ERROR: fgets failed in main\n"; input = line; if (input.length() > 0) { switch (input[0]) { Index: utilities/gbfidx.cpp =================================================================== --- utilities/gbfidx.cpp (revision 2419) +++ utilities/gbfidx.cpp (working copy) @@ -53,7 +53,7 @@ int main(int argc, char **argv) { long pos, offset; - int num1, num2, rangemax; + int num1, num2, rangemax, w; char startflag = 0; short size; @@ -65,18 +65,30 @@ num1 = key1.Chapter(); num2 = key1.Verse(); pos = 0; - write(bfp, &pos, 4); /* Book offset for testament intros */ + w = write(bfp, &pos, 4); /* Book offset for testament intros */ + if (w != 4) + perror("ERROR: write failed in main"); pos = 4; - write(cfp, &pos, 4); /* Chapter offset for testament intro */ + w = write(cfp, &pos, 4); /* Chapter offset for testament intro */ + if (w != 4) + perror("ERROR: write failed in main"); /* Right now just zero out intros until parsing correctly */ pos = 0; size = 0; - write(vfp, &pos, 4); /* Module intro */ - write(vfp, &size, 2); - write(vfp, &pos, 4); /* Testament intro */ - write(vfp, &size, 2); + w = write(vfp, &pos, 4); /* Module intro */ + if (w != 4) + perror("ERROR: write failed in main"); + w = write(vfp, &size, 2); + if (w != 2) + perror("ERROR: write failed in main"); + w = write(vfp, &pos, 4); /* Testament intro */ + if (w != 4) + perror("ERROR: write failed in main"); + w = write(vfp, &size, 2); + if (w != 2) + perror("ERROR: write failed in main"); while(!findbreak(fp, &offset, &num1, &num2, &rangemax, &size)) { if (!startflag) { @@ -120,6 +132,7 @@ void writeidx(VerseKey &key1, VerseKey &key2, VerseKey &key3, long offset, short size) { + int w; long pos; short tmp; @@ -127,26 +140,48 @@ if (key1.Verse() == 1) { // new chapter if (key1.Chapter() == 1) { // new book pos = lseek(cfp, 0, SEEK_CUR); - write(bfp, &pos, 4); + w = write(bfp, &pos, 4); + if (w != 2) + perror("ERROR: write failed in writeidx"); pos = lseek(vfp, 0, SEEK_CUR); /* Book intro (cps) */ - write(cfp, &pos, 4); - write(vfp, &chapoffset, 4); /* Book intro (vss) set to same as chap for now(it should be chap 1 which usually contains the book into anyway)*/ - write(vfp, &chapsize, 2); + w = write(cfp, &pos, 4); + if (w != 2) + perror("ERROR: write failed in writeidx"); + w = write(vfp, &chapoffset, 4); /* Book intro (vss) set to same as chap for now(it should be chap 1 which usually contains the book into anyway)*/ + if (w != 2) + perror("ERROR: write failed in writeidx"); + w = write(vfp, &chapsize, 2); + if (w != 2) + perror("ERROR: write failed in writeidx"); } pos = lseek(vfp, 0, SEEK_CUR); - write(cfp, &pos, 4); - write(vfp, &chapoffset, 4); /* Chapter intro */ - write(vfp, &chapsize, 2); + w = write(cfp, &pos, 4); + if (w != 4) + perror("ERROR: write failed in writeidx"); + w = write(vfp, &chapoffset, 4); /* Chapter intro */ + if (w != 4) + perror("ERROR: write failed in writeidx"); + w = write(vfp, &chapsize, 2); + if (w != 2) + perror("ERROR: write failed in writeidx"); } if (key1 >= key2) { - write(vfp, &offset, 4); - write(vfp, &size, 2); + w = write(vfp, &offset, 4); + if (w != 4) + perror("ERROR: write failed in writeidx"); + w = write(vfp, &size, 2); + if (w != 2) + perror("ERROR: write failed in writeidx"); } else { pos = 0; tmp = 0; - write(vfp, &pos, 4); - write(vfp, &tmp, 2); + w = write(vfp, &pos, 4); + if (w != 4) + perror("ERROR: write failed in writeidx"); + w = write(vfp, &tmp, 2); + if (w != 2) + perror("ERROR: write failed in writeidx"); } } } Index: utilities/genbookutil.cpp =================================================================== --- utilities/genbookutil.cpp (revision 2419) +++ utilities/genbookutil.cpp (working copy) @@ -48,9 +48,11 @@ void setLocalName(TreeKeyIdx *treeKey) { - char buf[1023]; + char buf[1023], *c; std::cout << "Enter New Node Name: "; - fgets(buf, 1000, stdin); + c = fgets(buf, 1000, stdin); + if (c == NULL) + std::cerr << "ERROR: fgets failed in setLocalName\n"; SWBuf name = buf; treeKey->setLocalName(name.trim()); treeKey->save(); @@ -58,18 +60,22 @@ void gotoPath(TreeKeyIdx *treeKey) { - char buf[1023]; + char buf[1023], *c; std::cout << "Enter Path: "; - fgets(buf, 1000, stdin); + c = fgets(buf, 1000, stdin); + if (c == NULL) + std::cerr << "ERROR: fgets failed in gotoPath\n"; SWBuf path = buf; (*treeKey) = path.trim(); } void assurePath(TreeKeyIdx *treeKey) { - char buf[1023]; + char buf[1023], *c; std::cout << "Enter Path: "; - fgets(buf, 1000, stdin); + c = fgets(buf, 1000, stdin); + if (c == NULL) + std::cerr << "ERROR: fgets failed in assurePath\n"; SWBuf path = buf; treeKey->assureKeyPath(path.trim()); } @@ -86,10 +92,12 @@ SWBuf body; TreeKeyIdx *treeKey = (TreeKeyIdx *)(SWKey *)(*book); if (treeKey->getOffset()) { - char buf[1023]; + char buf[1023], *c; std::cout << "Enter New Entry Text ('.' on a line by itself to end): \n"; do { - fgets(buf, 1000, stdin); + c = fgets(buf, 1000, stdin); + if (c == NULL) + std::cerr << "ERROR: fgets failed in setEntryText\n"; SWBuf text = buf; text.trim(); if ((text[0] == '.') && (text[1] == 0)) @@ -106,9 +114,11 @@ void appendSibbling(TreeKeyIdx *treeKey) { if (treeKey->getOffset()) { - char buf[1023]; + char buf[1023], *c; std::cout << "Enter New Sibbling Name: "; - fgets(buf, 1000, stdin); + c = fgets(buf, 1000, stdin); + if (c == NULL) + std::cerr << "ERROR: fgets failed in appendSibbling\n"; SWBuf name = buf; treeKey->append(); treeKey->setLocalName(name.trim()); @@ -119,9 +129,11 @@ void appendChild(TreeKeyIdx *treeKey) { - char buf[1023]; + char buf[1023], *c; std::cout << "Enter New Child Name: "; - fgets(buf, 1000, stdin); + c = fgets(buf, 1000, stdin); + if (c == NULL) + std::cerr << "ERROR: fgets failed in appendChild\n"; SWBuf name = buf; treeKey->appendChild(); treeKey->setLocalName(name.trim()); @@ -163,11 +175,13 @@ treeKey = (TreeKeyIdx *)(SWKey *)(*book); SWBuf input; - char line[1024]; + char line[1024], *c; do { std::cout << "[" << treeKey->getText() << "] > "; - fgets(line, 1000, stdin); + c = fgets(line, 1000, stdin); + if (c == NULL) + std::cerr << "ERROR: fgets failed in main\n"; input = line; input.trim(); if (input.length() > 0) { Index: utilities/vpl2mod.cpp =================================================================== --- utilities/vpl2mod.cpp (revision 2419) +++ utilities/vpl2mod.cpp (working copy) @@ -67,14 +67,18 @@ break; } - int size = (lseek(fd, 0, SEEK_CUR) - index) - 1; + int r, size = (lseek(fd, 0, SEEK_CUR) - index) - 1; *buf = new char [ size + 1 ]; if (size > 0) { lseek(fd, index, SEEK_SET); - read(fd, *buf, size); - read(fd, &ch, 1); //pop terminating char + r = read(fd, *buf, size); + if (r != size) + std::cerr <<"ERROR: short read in readline\n"; + r = read(fd, &ch, 1); //pop terminating char + if (r != size) + std::cerr <<"ERROR: short read of terminating char in readline\n"; (*buf)[size] = 0; // clean up any trailing junk on buf Index: utilities/installmgr.cpp =================================================================== --- utilities/installmgr.cpp (revision 2419) +++ utilities/installmgr.cpp (working copy) @@ -62,8 +62,10 @@ cout << "then type yes at the prompt\n\n"; cout << "enable? [no] "; - char prompt[10]; - fgets(prompt, 9, stdin); + char prompt[10], *c; + c = fgets(prompt, 9, stdin); + if (c == NULL) + std::cerr <<"ERROR: fgets failed in isUserDisclaimerConfirmed\n"; confirmed = (!strcmp(prompt, "yes\n")); } return confirmed; Index: utilities/step2vpl.cpp =================================================================== --- utilities/step2vpl.cpp (revision 2419) +++ utilities/step2vpl.cpp (working copy) @@ -218,93 +218,169 @@ void readVersion(int fd, Version *versionRecord) { + int r; - read(fd, &(versionRecord->versionRecordSize), 2); - read(fd, &(versionRecord->publisherID), 2); - read(fd, &(versionRecord->bookID), 2); - read(fd, &(versionRecord->setID), 2); - read(fd, &(versionRecord->conversionProgramVerMajor), 1); - read(fd, &(versionRecord->conversionProgramVerMinor), 1); - read(fd, &(versionRecord->leastCompatSTEPVerMajor), 1); - read(fd, &(versionRecord->leastCompatSTEPVerMinor), 1); - read(fd, &(versionRecord->encryptionType), 1); - read(fd, &(versionRecord->editionID), 1); - read(fd, &(versionRecord->modifiedBy), 2); + r = read(fd, &(versionRecord->versionRecordSize), 2); + if (r != 2) + perror("ERROR: read failed in readVersion"); + + r = read(fd, &(versionRecord->publisherID), 2); + if (r != 2) + perror("ERROR: read failed in readVersion"); + r = read(fd, &(versionRecord->bookID), 2); + if (r != 2) + perror("ERROR: read failed in readVersion"); + r = read(fd, &(versionRecord->setID), 2); + if (r != 2) + perror("ERROR: read failed in readVersion"); + r = read(fd, &(versionRecord->conversionProgramVerMajor), 1); + if (r != 1) + perror("ERROR: read failed in readVersion"); + r = read(fd, &(versionRecord->conversionProgramVerMinor), 1); + if (r != 1) + perror("ERROR: read failed in readVersion"); + r = read(fd, &(versionRecord->leastCompatSTEPVerMajor), 1); + if (r != 1) + perror("ERROR: read failed in readVersion"); + r = read(fd, &(versionRecord->leastCompatSTEPVerMinor), 1); + if (r != 1) + perror("ERROR: read failed in readVersion"); + r = read(fd, &(versionRecord->encryptionType), 1); + if (r != 1) + perror("ERROR: read failed in readVersion"); + r = read(fd, &(versionRecord->editionID), 1); + if (r != 1) + perror("ERROR: read failed in readVersion"); + r = read(fd, &(versionRecord->modifiedBy), 2); + if (r != 2) + perror("ERROR: read failed in readVersion"); int skip = versionRecord->versionRecordSize - 16/*sizeof(struct Version*/; if (skip) { char *skipbuf = new char[skip]; - read(fd, skipbuf, skip); + r = read(fd, skipbuf, skip); + if (r != skip) + perror("ERROR: read failed in readVersion"); delete [] skipbuf; } } void readSectionsHeader(int fd, SectionsHeader *sectionsHeaderRecord) { + int r; - read(fd, &(sectionsHeaderRecord->sectionsHeaderRecordSize), 2); - read(fd, &(sectionsHeaderRecord->levelEntriesCount), 4); - read(fd, &(sectionsHeaderRecord->glossEntriesCount), 4); - read(fd, &(sectionsHeaderRecord->levelEntriesSize), 2); - read(fd, &(sectionsHeaderRecord->reserved), 4); + r = read(fd, &(sectionsHeaderRecord->sectionsHeaderRecordSize), 2); + if (r != 2) + perror("ERROR: read failed in readSectionsHeader"); + r = read(fd, &(sectionsHeaderRecord->levelEntriesCount), 4); + if (r != 4) + perror("ERROR: read failed in readSectionsHeader"); + r = read(fd, &(sectionsHeaderRecord->glossEntriesCount), 4); + if (r != 4) + perror("ERROR: read failed in readSectionsHeader"); + r = read(fd, &(sectionsHeaderRecord->levelEntriesSize), 2); + if (r != 2) + perror("ERROR: read failed in readSectionsHeader"); + r = read(fd, &(sectionsHeaderRecord->reserved), 4); + if (r != 4) + perror("ERROR: read failed in readSectionsHeader"); int skip = sectionsHeaderRecord->sectionsHeaderRecordSize - 16/*sizeof(struct ViewableHeader)*/; if (skip) { char *skipbuf = new char[skip]; - read(fd, skipbuf, skip); + r = read(fd, skipbuf, skip); + if (r != skip) + perror("ERROR: read failed in readSectionsHeader"); delete [] skipbuf; } } void readViewableHeader(int fd, ViewableHeader *viewableHeaderRecord) { + int r; - read(fd, &(viewableHeaderRecord->viewableHeaderRecordSize), 2); - read(fd, &(viewableHeaderRecord->viewableBlocksCount), 4); - read(fd, &(viewableHeaderRecord->glossBlocksCount), 4); - read(fd, &(viewableHeaderRecord->compressionType), 1); - read(fd, &(viewableHeaderRecord->reserved1), 1); - read(fd, &(viewableHeaderRecord->blockEntriesSize), 2); - read(fd, &(viewableHeaderRecord->reserved2), 2); + r = read(fd, &(viewableHeaderRecord->viewableHeaderRecordSize), 2); + if (r != 2) + perror("ERROR: read failed in readViewableHeader"); + r = read(fd, &(viewableHeaderRecord->viewableBlocksCount), 4); + if (r != 4) + perror("ERROR: read failed in readViewableHeader"); + r = read(fd, &(viewableHeaderRecord->glossBlocksCount), 4); + if (r != 4) + perror("ERROR: read failed in readViewableHeader"); + r = read(fd, &(viewableHeaderRecord->compressionType), 1); + if (r != 1) + perror("ERROR: read failed in readViewableHeader"); + r = read(fd, &(viewableHeaderRecord->reserved1), 1); + if (r != 1) + perror("ERROR: read failed in readViewableHeader"); + r = read(fd, &(viewableHeaderRecord->blockEntriesSize), 2); + if (r != 2) + perror("ERROR: read failed in readViewableHeader"); + r = read(fd, &(viewableHeaderRecord->reserved2), 2); + if (r != 2) + perror("ERROR: read failed in readViewableHeader"); int skip = viewableHeaderRecord->viewableHeaderRecordSize - 16/*sizeof(struct ViewableHeader)*/; if (skip) { char *skipbuf = new char[skip]; - read(fd, skipbuf, skip); + r = read(fd, skipbuf, skip); + if (r != skip) + perror("ERROR: read failed in readViewableHeader"); delete [] skipbuf; } } void readVSyncHeader(int fd, VSyncHeader *vSyncHeaderRecord) { + int r; - read(fd, &(vSyncHeaderRecord->vSyncHeaderRecordSize), 2); - read(fd, &(vSyncHeaderRecord->startBookNumber), 2); - read(fd, &(vSyncHeaderRecord->endBookNumber), 2); - read(fd, &(vSyncHeaderRecord->bookPointerEntriesSize), 2); - read(fd, &(vSyncHeaderRecord->syncPointEntriesSize), 2); - read(fd, &(vSyncHeaderRecord->reserved1_1), 4); - read(fd, &(vSyncHeaderRecord->reserved1_2), 2); + r = read(fd, &(vSyncHeaderRecord->vSyncHeaderRecordSize), 2); + if (r != 2) + perror("ERROR: read failed in readVSyncHeader"); + r = read(fd, &(vSyncHeaderRecord->startBookNumber), 2); + if (r != 2) + perror("ERROR: read failed in readVSyncHeader"); + r = read(fd, &(vSyncHeaderRecord->endBookNumber), 2); + if (r != 2) + perror("ERROR: read failed in readVSyncHeader"); + r = read(fd, &(vSyncHeaderRecord->bookPointerEntriesSize), 2); + if (r != 2) + perror("ERROR: read failed in readVSyncHeader"); + r = read(fd, &(vSyncHeaderRecord->syncPointEntriesSize), 2); + if (r != 2) + perror("ERROR: read failed in readVSyncHeader"); + r = read(fd, &(vSyncHeaderRecord->reserved1_1), 4); + if (r != 4) + perror("ERROR: read failed in readVSyncHeader"); + r = read(fd, &(vSyncHeaderRecord->reserved1_2), 2); + if (r != 2) + perror("ERROR: read failed in readVSyncHeader"); int skip = vSyncHeaderRecord->vSyncHeaderRecordSize - 16/*sizeof(VSyncHeader)*/; if (skip) { char *skipbuf = new char[skip]; - read(fd, skipbuf, skip); + r = read(fd, skipbuf, skip); + if (r != skip) + perror("ERROR: read failed in readVSyncHeader"); delete [] skipbuf; } } void readViewableBlockText(int fd, ViewableBlock *vb, char **buf) { + int r; unsigned long size = vb->size; *buf = new char [ ((vb->size > vb->uncompressedSize) ? vb->size : vb->uncompressedSize) + 1 ]; lseek(fd, vb->offset, SEEK_SET); - read(fd, *buf, vb->size); + r = read(fd, *buf, vb->size); + if (r != vb->size) + perror("ERROR: read failed in readViewableBlockText"); compress->zBuf(&size, *buf); strcpy(*buf, compress->Buf()); @@ -312,35 +388,53 @@ void readViewableBlock(int fd, ViewableBlock *vb) { + int r; - read(fd, &(vb->offset), 4); - read(fd, &(vb->uncompressedSize), 4); - read(fd, &(vb->size), 4); + r = read(fd, &(vb->offset), 4); + if (r != 4) + perror("ERROR: read failed in readViewableBlock"); + r = read(fd, &(vb->uncompressedSize), 4); + if (r != 4) + perror("ERROR: read failed in readViewableBlock"); + r = read(fd, &(vb->size), 4); + if (r != 4) + perror("ERROR: read failed in readViewableBlock"); } void readHeaderControlWordAreaText(int fd, char **buf) { + int r; long headerControlWordAreaSize; - read(fd, &headerControlWordAreaSize, 4); + r = read(fd, &headerControlWordAreaSize, 4); + if (r != 4) + perror("ERROR: read failed in readHeaderControlWordAreaText"); *buf = new char [headerControlWordAreaSize + 1]; - read(fd, *buf, headerControlWordAreaSize); + r = read(fd, *buf, headerControlWordAreaSize); + if (r != headerControlWordAreaSize) + perror("ERROR: read failed in readHeaderControlWordAreaText"); (*buf)[headerControlWordAreaSize] = 0; } void readVSyncBooksInfo(int fd, VSyncHeader *vSyncHeaderRecord, VSyncBooksInfo **vSyncBooksInfo) { + int r; int bookCount = vSyncHeaderRecord->endBookNumber - vSyncHeaderRecord->startBookNumber; *vSyncBooksInfo = new VSyncBooksInfo[bookCount]; for (int i = 0; i <= bookCount; i++) { - read(fd, &(*vSyncBooksInfo)[i].offset, 4); - read(fd, &(*vSyncBooksInfo)[i].count, 2); + r = read(fd, &(*vSyncBooksInfo)[i].offset, 4); + if (r != 4) + perror("ERROR: read failed in readVSyncBooksInfo"); + r = read(fd, &(*vSyncBooksInfo)[i].count, 2); + if (r != 2) + perror("ERROR: read failed in readVSyncBooksInfo"); } } void displayBook(int fdbook, int fdviewable, int fdvsync, int fdsections, VSyncBooksInfo *vSyncBooksInfo) { + int r; VSyncPoint vSyncPoint; lseek(fdvsync, vSyncBooksInfo->offset, SEEK_SET); @@ -351,9 +445,15 @@ char *sectionName; char *verseText; - read(fdvsync, &(vSyncPoint.chapter), 2); - read(fdvsync, &(vSyncPoint.verse), 2); - read(fdvsync, &(vSyncPoint.offset), 4); + r = read(fdvsync, &(vSyncPoint.chapter), 2); + if (r != 2) + perror("ERROR: read failed in displayBook"); + r = read(fdvsync, &(vSyncPoint.verse), 2); + if (r != 2) + perror("ERROR: read failed in displayBook"); + r = read(fdvsync, &(vSyncPoint.offset), 4); + if (r != 4) + perror("ERROR: read failed in displayBook"); vSyncPoint.offset = SECTIONSLEVELSTART + (vSyncPoint.offset * SECTIONSLEVELSIZE); lseek(fdsections, vSyncPoint.offset, SEEK_SET); readSectionLevelInfo(fdsections, §ionLevelInfo); @@ -408,26 +508,50 @@ void readSectionName(int fd, SectionLevelInfo *sli, char **name) { + int r; short size; lseek(fd, sli->nameOffset, SEEK_SET); - read(fd, &size, 2); + r = read(fd, &size, 2); + if (r != 2) + perror("ERROR: read failed in readSectionName"); *name = new char [ size + 1 ]; - read(fd, *name, size); + r = read(fd, *name, size); + if (r != size) + perror("ERROR: read failed in readSectionName"); (*name)[size] = 0; } void readSectionLevelInfo(int fd, SectionLevelInfo *sli) { + int r; - read(fd, &(sli->parentOffset), 4); - read(fd, &(sli->previousOffset), 4); - read(fd, &(sli->nextOffset), 4); - read(fd, &(sli->viewableOffset), 4); + r = read(fd, &(sli->parentOffset), 4); + if (r != 4) + perror("ERROR: read failed in readSectionLevelInfo"); + r = read(fd, &(sli->previousOffset), 4); + if (r != 4) + perror("ERROR: read failed in readSectionLevelInfo"); + r = read(fd, &(sli->nextOffset), 4); + if (r != 4) + perror("ERROR: read failed in readSectionLevelInfo"); + r = read(fd, &(sli->viewableOffset), 4); + if (r != 4) + perror("ERROR: read failed in readSectionLevelInfo"); sli->viewableOffset = VIEWABLEBLOCKSTART + (VIEWABLEBLOCKSIZE * sli->viewableOffset); - read(fd, &(sli->startLevel), 2); - read(fd, &(sli->level), 1); - read(fd, &(sli->nameOffset), 4); - read(fd, &(sli->outSync_1), 4); - read(fd, &(sli->outSync_2), 2); + r = read(fd, &(sli->startLevel), 2); + if (r != 2) + perror("ERROR: read failed in readSectionLevelInfo"); + r = read(fd, &(sli->level), 1); + if (r != 1) + perror("ERROR: read failed in readSectionLevelInfo"); + r = read(fd, &(sli->nameOffset), 4); + if (r != 4) + perror("ERROR: read failed in readSectionLevelInfo"); + r = read(fd, &(sli->outSync_1), 4); + if (r != 4) + perror("ERROR: read failed in readSectionLevelInfo"); + r = read(fd, &(sli->outSync_2), 2); + if (r != 2) + perror("ERROR: read failed in readSectionLevelInfo"); } void cleanBuf(char *buf) { Index: utilities/cipherraw.cpp =================================================================== --- utilities/cipherraw.cpp (revision 2419) +++ utilities/cipherraw.cpp (working copy) @@ -43,7 +43,7 @@ SWCipher *zobj; VerseKey key; RawVerse *rawdrv; - int ofd[2], oxfd[2]; + int ofd[2], oxfd[2], w; long tmpoff = 0, offset, loffset = 0, lzoffset = 0; unsigned short size, lsize = 0, lzsize; char *tmpbuf; @@ -69,10 +69,18 @@ delete [] tmpbuf; printf("\n"); - write(oxfd[0], &lzoffset, 4); - write(oxfd[0], &lzsize, 2); - write(oxfd[1], &lzoffset, 4); - write(oxfd[1], &lzsize, 2); + w = write(oxfd[0], &lzoffset, 4); + if (w < 0) + perror("ERROR: write failed in main"); + w = write(oxfd[0], &lzsize, 2); + if (w < 0) + perror("ERROR: write failed in main"); + w = write(oxfd[1], &lzoffset, 4); + if (w < 0) + perror("ERROR: write failed in main"); + w = write(oxfd[1], &lzsize, 2); + if (w < 0) + perror("ERROR: write failed in main"); key.AutoNormalize(0); key.Headings(1); @@ -84,8 +92,13 @@ printf("using previous offset,size %d\n", size); offset = lseek(oxfd[key.Testament() - 1], 0, SEEK_CUR); printf("%ld %ld %d \n", offset, lzoffset, lzsize); - write(oxfd[key.Testament() - 1], &lzoffset, 4); - write(oxfd[key.Testament() - 1], &lzsize, 2); + w = write(oxfd[key.Testament() - 1], &lzoffset, 4); + if (w < 0) + perror("ERROR: write failed in main"); + + w = write(oxfd[key.Testament() - 1], &lzsize, 2); + if (w < 0) + perror("ERROR: write failed in main"); } else { lsize = size; @@ -102,13 +115,23 @@ offset = lseek(ofd[key.Testament() - 1], 0, SEEK_CUR); tmpoff = lseek(oxfd[key.Testament() - 1], 0, SEEK_CUR); printf("%s: (%ld) NEW offset: %ld; size: %d\n", (const char *)key, tmpoff, offset, size); - write(oxfd[key.Testament() - 1], &offset, 4); + w = write(oxfd[key.Testament() - 1], &offset, 4); + if (w < 0) + perror("ERROR: write failed in main"); + unsigned long ulSize = size; - if (size) - write(ofd[key.Testament() - 1], zobj->cipherBuf(&ulSize), size); + if (size) { + w = write(ofd[key.Testament() - 1], zobj->cipherBuf(&ulSize), size); + if (w < 0) + perror("ERROR: write failed in main"); + } + size = (unsigned int)ulSize; lzoffset = offset; - write(oxfd[key.Testament() - 1], &size, 2); + w = write(oxfd[key.Testament() - 1], &size, 2); + if (w < 0) + perror("ERROR: write failed in main"); + lzsize = size; } }