00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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 }