From 8230293d65e0383590534528c3822409334feebb Mon Sep 17 00:00:00 2001
From: Tinny Ng <tng@apache.org>
Date: Fri, 1 Nov 2002 22:05:57 +0000
Subject: [PATCH] Samples/Test update: Issue error if the list file failed to
 open.

git-svn-id: https://svn.apache.org/repos/asf/xerces/c/trunk@174308 13f79535-47bb-0310-9956-ffa450edef68
---
 samples/DOMCount/DOMCount.cpp                       | 12 +++++++-----
 samples/SAX2Count/SAX2Count.cpp                     | 12 ++++++++++--
 samples/SAXCount/SAXCount.cpp                       | 12 ++++++++++--
 tests/DOM/DeprecatedDOMCount/DeprecatedDOMCount.cpp |  9 +++++++--
 4 files changed, 34 insertions(+), 11 deletions(-)

diff --git a/samples/DOMCount/DOMCount.cpp b/samples/DOMCount/DOMCount.cpp
index 8f9239ff2..0cfd244b0 100644
--- a/samples/DOMCount/DOMCount.cpp
+++ b/samples/DOMCount/DOMCount.cpp
@@ -78,8 +78,6 @@
 #include <fstream.h>
 
 
-
-
 // ---------------------------------------------------------------------------
 //  This is a simple program which invokes the DOMParser to build a DOM
 //  tree for the specified input file. It then walks the tree and counts
@@ -123,7 +121,6 @@ static int countChildElements(DOMNode *n)
     return count;
 }
 
-
 // ---------------------------------------------------------------------------
 //
 //   main
@@ -278,13 +275,18 @@ int main(int argC, char* argV[])
 
     // the input is a list file
     if (doList)
-        fin.open(argV[argInd]);
+        fin.open(argV[argInd],ios::nocreate);
+
+    if (fin.fail()) {
+        cerr <<"Cannot open the list file: " << argV[argInd] << endl;
+        return 2;
+    }
 
     while (more)
     {
         char fURI[1000];
         //initialize the array to zeros
-        memset(fURI,0,strlen(fURI));
+        memset(fURI,0,sizeof(fURI));
 
         if (doList) {
             if (! fin.eof() ) {
diff --git a/samples/SAX2Count/SAX2Count.cpp b/samples/SAX2Count/SAX2Count.cpp
index 80f9ddde5..c82cbac89 100644
--- a/samples/SAX2Count/SAX2Count.cpp
+++ b/samples/SAX2Count/SAX2Count.cpp
@@ -56,6 +56,9 @@
 
 /*
 * $Log$
+* Revision 1.20  2002/11/01 22:05:57  tng
+* Samples/Test update: Issue error if the list file failed to open.
+*
 * Revision 1.19  2002/09/27 19:24:57  tng
 * Samples Fix: wrong length in memset
 *
@@ -315,13 +318,18 @@ int main(int argC, char* argV[])
 
     // the input is a list file
     if (doList)
-        fin.open(argV[argInd]);
+        fin.open(argV[argInd],ios::nocreate);
+
+    if (fin.fail()) {
+        cerr <<"Cannot open the list file: " << argV[argInd] << endl;
+        return 2;
+    }
 
     while (more)
     {
         char fURI[1000];
         //initialize the array to zeros
-        memset(fURI,0,strlen(fURI));
+        memset(fURI,0,sizeof(fURI));
 
         if (doList) {
             if (! fin.eof() ) {
diff --git a/samples/SAXCount/SAXCount.cpp b/samples/SAXCount/SAXCount.cpp
index 58902728a..00f44c8b5 100644
--- a/samples/SAXCount/SAXCount.cpp
+++ b/samples/SAXCount/SAXCount.cpp
@@ -56,6 +56,9 @@
 
 /*
 * $Log$
+* Revision 1.23  2002/11/01 22:05:44  tng
+* Samples/Test update: Issue error if the list file failed to open.
+*
 * Revision 1.22  2002/09/27 19:25:10  tng
 * Samples Fix: wrong length in memset
 *
@@ -310,13 +313,18 @@ int main(int argC, char* argV[])
 
     // the input is a list file
     if (doList)
-        fin.open(argV[argInd]);
+        fin.open(argV[argInd],ios::nocreate);
+
+    if (fin.fail()) {
+        cerr <<"Cannot open the list file: " << argV[argInd] << endl;
+        return 2;
+    }
 
     while (true)
     {
         char fURI[1000];
         //initialize the array to zeros
-        memset(fURI,0,strlen(fURI));
+        memset(fURI,0,sizeof(fURI));
 
         if (doList) {
             if (! fin.eof() ) {
diff --git a/tests/DOM/DeprecatedDOMCount/DeprecatedDOMCount.cpp b/tests/DOM/DeprecatedDOMCount/DeprecatedDOMCount.cpp
index 71c573ba6..e8f204cc0 100644
--- a/tests/DOM/DeprecatedDOMCount/DeprecatedDOMCount.cpp
+++ b/tests/DOM/DeprecatedDOMCount/DeprecatedDOMCount.cpp
@@ -226,13 +226,18 @@ int main(int argC, char* argV[])
 
     // the input is a list file
     if (doList)
-        fin.open(argV[argInd]);
+        fin.open(argV[argInd],ios::nocreate);
+
+    if (fin.fail()) {
+        cerr <<"Cannot open the list file: " << argV[argInd] << endl;
+        return 2;
+    }
 
     while (more)
     {
         char fURI[1000];
         //initialize the array to zeros
-        memset(fURI,0,strlen(fURI));
+        memset(fURI,0,sizeof(fURI));
 
         if (doList) {
             if (! fin.eof() ) {
-- 
GitLab