HP OpenVMS Systemsask the wizard |
The Question is: For OpenVMS DEC C++ 5.6 for VAX and DEC C++ 6.0 for ALPHA, using the CXX compiler, we want to have multiple processes write to a common log file using standard cerr <<... The answer to question 2867 about shared log files was teasing, but I cant see how to get there from C++. What is the C++ class interface to RMS? I want to say something like the 'regular' C fp = fopen( fn, "w", "shr=get,put,upd", "rat=cr", "rfm=var", "etx=rec"); and all I can find in the Alpha C++ on line class reference manuals is a member function that takes a third integer, for example: ofstream( const char* name, int mode, int prot ); where prot defaults to openprot=0644 which is owner read write, group and world read. The Answer is : #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <fstream.hxx> #include <iostream.hxx> main () { fstream outfile; int fd, pid = getpid(); fd = open("fstream.log", O_CREAT|O_RDWR|O_APPEND, 0, "ctx=rec", "shr=get,put,upd"); if ( fd == -1 ) { // trap errors... perror("open"); exit(EXIT_FAILURE); } outfile.attach(fd); if (outfile.fail()) cout << "Failed to open the file" << endl; for (int i = 0; i < 1000; ++i) outfile << i << ": One line for the file from: " << pid << endl; if (outfile.good()) cout << "No problem writing to file" << endl; exit(EXIT_SUCCESS); }
|