Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

TestAtomicFile.C

Go to the documentation of this file.
00001 // TestAtomicFile.C
00002 
00003 // Copyright (C) 2001, Compaq Computer Corporation
00004 
00005 // This file is part of Vesta.
00006 
00007 // Vesta is free software; you can redistribute it and/or
00008 // modify it under the terms of the GNU Lesser General Public
00009 // License as published by the Free Software Foundation; either
00010 // version 2.1 of the License, or (at your option) any later version.
00011 
00012 // Vesta is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015 // Lesser General Public License for more details.
00016 
00017 // You should have received a copy of the GNU Lesser General Public
00018 // License along with Vesta; if not, write to the Free Software
00019 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 
00021 // Last modified on Sat May 29 17:55:52 EDT 2004 by ken@xorian.net
00022 //      modified on Mon May  3 15:55:17 PDT 1999 by heydon
00023 //      modified on Thu Jan 19 12:19:25 PST 1995 by mann
00024 //
00025 // Test program for AtomicFile interface
00026 //
00027 
00028 #include "AtomicFile.H"
00029 #include <iostream>
00030 #include <unistd.h>
00031 #include <errno.h>
00032 #include <string.h>
00033 
00034 using std::cout;
00035 using std::cerr;
00036 using std::cin;
00037 using std::endl;
00038 using std::ios;
00039 
00040 int main()
00041 {
00042     char reply1[999];
00043     cout << "open filename: ";
00044     cin >> reply1; 
00045     AtomicFile foo;
00046     foo.open(reply1, ios::out);
00047     if (!foo) {
00048       cerr << "error on open: " << strerror(errno)
00049            << " (" << errno << ")" << endl;
00050       return 1;
00051     }
00052     cout << "write data: ";
00053     cin >> reply1; 
00054     foo << reply1;
00055     if (!foo) {
00056       cerr << "error on write: " << strerror(errno)
00057            << " (" << errno << ")" << endl;
00058       return 1;
00059     }
00060     cout << "cleanup? ";
00061     cin >> reply1; 
00062     if (reply1[0] == 'y') {
00063         AtomicFile::cleanup(".");
00064     }
00065     cout << "flush? ";
00066     cin >> reply1; 
00067     if (reply1[0] == 'y') {
00068         foo.flush();
00069         if (foo.fail()) {
00070           cerr << "error on flush: " << strerror(errno)
00071                << " (" << errno << ")" << endl;
00072           return 1;
00073         }
00074     }
00075     cout << "close? ";
00076     cin >> reply1; 
00077     if (reply1[0] == 'y') {
00078         foo.close();
00079         if (!foo) {
00080           cerr << "error on close: " << strerror(errno)
00081                << " (" << errno << ")" << endl;
00082           return 1;
00083         }
00084     }
00085     do {
00086         cout << "return? ";
00087         cin >> reply1; 
00088     } while (reply1[0] != 'y');
00089     return 0;
00090 }

Generated on Mon May 8 00:48:30 2006 for Vesta by  doxygen 1.4.2