#include <unistd.h>#include <errno.h>#include <string.h>#include <sys/stat.h>#include <ctype.h>#include "common.h"#include "InfoStream.h"#include "charm++.h"Go to the source code of this file.
Functions | |
| char * | NAMD_stringdup (const char *s) |
| void | NAMD_quit (const char *err_msg) |
| void | NAMD_die (const char *err_msg) |
| void | NAMD_err (const char *err_msg) |
| void | NAMD_bug (const char *err_msg) |
| void | NAMD_backup_file (const char *filename, const char *extension) |
| void | NAMD_write (int fd, const char *buf, size_t count) |
| FILE * | Fopen (const char *filename, const char *mode) |
| int | Fclose (FILE *fout) |
|
|
Definition at line 271 of file common.C. Referenced by ConfigList::ConfigList(), parm::genclose(), PDB::PDB(), read_binary_file(), and Parameters::read_parameter_file(). 00272 {
00273 int rc = -1;
00274 #if !defined(NOCOMPRESSED)
00275 rc = pclose(fout);
00276 #endif
00277 if (rc == -1) // stream not associated with a popen()
00278 {
00279 rc = fclose(fout);
00280 }
00281 return rc;
00282 } /* Fclose() */
|
|
||||||||||||
|
Definition at line 177 of file common.C. References iout. Referenced by ConfigList::ConfigList(), parm::genopen(), GridforceFullMainGrid::initialize(), PDB::PDB(), read_binary_file(), and Parameters::read_parameter_file(). 00178 {
00179 struct stat buf;
00180 // check if basic filename exists (and not a directory)
00181
00182 #if defined(NOCOMPRESSED)
00183 if (!stat(filename,&buf))
00184 {
00185 FILE *rval;
00186 while ( ! (rval = fopen(filename,mode)) ) {
00187 if ( errno != EINTR ) break;
00188 }
00189 return(rval);
00190 }
00191 #else
00192 if (!stat(filename,&buf))
00193 {
00194 if (!S_ISDIR(buf.st_mode)) {
00195 FILE *rval;
00196 while ( ! (rval = fopen(filename,mode)) ) {
00197 if ( errno != EINTR ) break;
00198 }
00199 return(rval);
00200 }
00201 }
00202 // check for a compressed file
00203 char *realfilename;
00204 char *command;
00205 FILE *fout;
00206 command = (char *)malloc(strlen(filename)+25);
00207 // check for .Z (unix compress)
00208 sprintf(command,"zcat %s.Z",filename);
00209 realfilename = command+5;
00210 iout << "Command = " << command << "\n" << endi;
00211 iout << "Filename.Z = " << realfilename << "\n" << endi;
00212 if (!stat(realfilename,&buf))
00213 {
00214 if (!S_ISDIR(buf.st_mode))
00215 {
00216 fout = popen(command,mode);
00217 // on HP-UX, the first character(s) out of pipe may be
00218 // garbage! (Argh!)
00219 int C;
00220 do
00221 {
00222 C = fgetc(fout);
00223 // iout << "C is " << C << "\n" << endi;
00224 if (isalnum(C) || isspace(C))
00225 {
00226 ungetc(C,fout);
00227 C = -1; // outta loop
00228 }
00229 } while(C != -1);
00230 free(command);
00231 return(fout);
00232 }
00233 }
00234 // check for .gz (gzip)
00235 sprintf(command,"gzip -d -c %s.gz",filename);
00236 realfilename = command+11;
00237 iout << "Command = " << command << "\n" << endi;
00238 iout << "Filename.gz = " << realfilename << "\n" << endi;
00239 if (!stat(realfilename,&buf))
00240 {
00241 if (!S_ISDIR(buf.st_mode))
00242 {
00243 fout = popen(command,mode);
00244 // on HP-UX, the first character(s) out of pipe may be
00245 // garbage! (Argh!)
00246 int C;
00247 do
00248 {
00249 C = fgetc(fout);
00250 // iout << "C is " << C << "\n" << endi;
00251 if (isalnum(C) || isspace(C))
00252 {
00253 ungetc(C,fout);
00254 C = -1; // outta loop
00255 }
00256 } while(C != -1);
00257 free(command);
00258 return(fout);
00259 }
00260 }
00261 free(command);
00262 #endif /* !defined(NOCOMPRESSED) */
00263
00264 return(NULL);
00265 } /* Fopen() */
|
|
||||||||||||
|
Definition at line 118 of file common.C. References iERROR(), and iout. Referenced by Controller::adaptTempInit(), colvarproxy_namd::backup_file(), Controller::outputExtendedSystem(), Controller::outputFepEnergy(), Controller::outputTiEnergy(), and CollectionMaster::receiveDataStream(). 00119 {
00120 if (access(filename, F_OK) == 0) {
00121 if ( ! extension ) extension = ".BAK";
00122 char *backup = new char[strlen(filename)+strlen(extension)+1];
00123 strcpy(backup, filename);
00124 strcat(backup, extension);
00125 #if defined(WIN32) && !defined(__CYGWIN__)
00126 if ( remove(backup) ) if ( errno != ENOENT ) {
00127 char *sys_err_msg = strerror(errno);
00128 if ( ! sys_err_msg ) sys_err_msg = "(unknown error)";
00129 iout << iERROR << "Error on removing file "
00130 << backup << ": " << sys_err_msg << "\n" << endi;
00131 fflush(stdout);
00132 }
00133 #endif
00134 if ( rename(filename,backup) )
00135 {
00136 char *sys_err_msg = strerror(errno);
00137 if ( ! sys_err_msg ) sys_err_msg = "(unknown error)";
00138 iout << iERROR << "Error on renaming file " << filename
00139 << " to " << backup << ": " << sys_err_msg << "\n" << endi;
00140 fflush(stdout);
00141 // char errmsg[256];
00142 // sprintf(errmsg, "Error on renaming file %s to %s",filename,backup);
00143 // NAMD_err(errmsg);
00144 }
00145 delete [] backup;
00146 }
00147 }
|
|
|
|
|
Definition at line 89 of file common.C. Referenced by after_backend_init(), NAMD_write(), Controller::outputExtendedSystem(), PDB::PDB(), and PDB::write(). 00091 {
00092 char *sys_err_msg = strerror(errno);
00093 if ( ! sys_err_msg ) sys_err_msg = "(unknown error)";
00094 char *new_err_msg = new char[strlen(err_msg) + 20 + strlen(sys_err_msg)];
00095 sprintf(new_err_msg,"FATAL ERROR: %s: %s\n",err_msg, sys_err_msg);
00096 CkPrintf(new_err_msg);
00097 fflush(stdout);
00098 CmiAbort(new_err_msg);
00099 delete [] new_err_msg;
00100 }
|
|
|
Definition at line 63 of file common.C. Referenced by GlobalMasterIMD::get_vmd_forces(). 00065 {
00066 char *new_err_msg = new char[strlen(err_msg) + 20];
00067 sprintf(new_err_msg,"EXITING: %s\n",err_msg);
00068 CkPrintf(new_err_msg);
00069 fflush(stdout);
00070 CmiAbort(new_err_msg);
00071 delete [] new_err_msg;
00072 }
|
|
|
Copyright (c) 1995, 1996, 1997, 1998, 1999, 2000 by The Board of Trustees of the University of Illinois. All rights reserved. Definition at line 49 of file common.C. 00049 {
00050 char *rs;
00051
00052 if(!s)
00053 return NULL;
00054
00055 rs = new char[strlen(s) + 1];
00056 strcpy(rs,s);
00057
00058 return rs;
00059 }
|
|
||||||||||||||||
|
Definition at line 150 of file common.C. References NAMD_bug(), and NAMD_die(). 00150 {
00151 while ( count ) {
00152 #if defined(WIN32) && !defined(__CYGWIN__)
00153 long retval = _write(fd,buf,count);
00154 #else
00155 ssize_t retval = write(fd,buf,count);
00156 #endif
00157 if ( retval < 0 && errno == EINTR ) retval = 0;
00158 if ( retval < 0 ) NAMD_die(strerror(errno));
00159 if ( retval > count ) NAMD_bug("extra bytes written in NAMD_write()");
00160 buf += retval;
00161 count -= retval;
00162 }
00163 }
|
1.3.9.1