#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 255 of file common.C. Referenced by ConfigList::ConfigList(), parm::genclose(), PDB::PDB(), read_binary_file(), Parameters::read_parameter_file(), and Molecule::read_psf_file(). 00256 {
00257 int rc = -1;
00258 #if !defined(NOCOMPRESSED)
00259 rc = pclose(fout);
00260 #endif
00261 if (rc == -1) // stream not associated with a popen()
00262 {
00263 rc = fclose(fout);
00264 }
00265 return rc;
00266 } /* Fclose() */
|
|
||||||||||||
|
Definition at line 170 of file common.C. References iout. Referenced by ConfigList::ConfigList(), parm::genopen(), GridforceGrid::initialize(), PDB::PDB(), read_binary_file(), Parameters::read_parameter_file(), and Molecule::read_psf_file(). 00171 {
00172 struct stat buf;
00173 // check if basic filename exists (and not a directory)
00174
00175 #if defined(NOCOMPRESSED)
00176 if (!stat(filename,&buf))
00177 {
00178 return(fopen(filename,mode));
00179 }
00180 #else
00181 if (!stat(filename,&buf))
00182 {
00183 if (!S_ISDIR(buf.st_mode))
00184 return(fopen(filename,mode));
00185 }
00186 // check for a compressed file
00187 char *realfilename;
00188 char *command;
00189 FILE *fout;
00190 command = (char *)malloc(strlen(filename)+25);
00191 // check for .Z (unix compress)
00192 sprintf(command,"zcat %s.Z",filename);
00193 realfilename = command+5;
00194 iout << "Command = " << command << "\n" << endi;
00195 iout << "Filename.Z = " << realfilename << "\n" << endi;
00196 if (!stat(realfilename,&buf))
00197 {
00198 if (!S_ISDIR(buf.st_mode))
00199 {
00200 fout = popen(command,mode);
00201 // on HP-UX, the first character(s) out of pipe may be
00202 // garbage! (Argh!)
00203 int C;
00204 do
00205 {
00206 C = fgetc(fout);
00207 // iout << "C is " << C << "\n" << endi;
00208 if (isalnum(C) || isspace(C))
00209 {
00210 ungetc(C,fout);
00211 C = -1; // outta loop
00212 }
00213 } while(C != -1);
00214 free(command);
00215 return(fout);
00216 }
00217 }
00218 // check for .gz (gzip)
00219 sprintf(command,"gzip -d -c %s.gz",filename);
00220 realfilename = command+11;
00221 iout << "Command = " << command << "\n" << endi;
00222 iout << "Filename.gz = " << realfilename << "\n" << endi;
00223 if (!stat(realfilename,&buf))
00224 {
00225 if (!S_ISDIR(buf.st_mode))
00226 {
00227 fout = popen(command,mode);
00228 // on HP-UX, the first character(s) out of pipe may be
00229 // garbage! (Argh!)
00230 int C;
00231 do
00232 {
00233 C = fgetc(fout);
00234 // iout << "C is " << C << "\n" << endi;
00235 if (isalnum(C) || isspace(C))
00236 {
00237 ungetc(C,fout);
00238 C = -1; // outta loop
00239 }
00240 } while(C != -1);
00241 free(command);
00242 return(fout);
00243 }
00244 }
00245 free(command);
00246 #endif /* !defined(NOCOMPRESSED) */
00247
00248 return(NULL);
00249 } /* Fopen() */
|
|
||||||||||||
|
Definition at line 117 of file common.C. References iERROR(), and iout. Referenced by Controller::outputExtendedSystem(), Controller::outputFepEnergy(), Controller::outputTiEnergy(), and CollectionMaster::receiveDataStream(). 00118 {
00119 struct stat sbuf;
00120 if (stat(filename, &sbuf) == 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 remove(backup);
00127 #endif
00128 if ( rename(filename,backup) )
00129 {
00130 char *sys_err_msg = strerror(errno);
00131 if ( ! sys_err_msg ) sys_err_msg = "(unknown error)";
00132 iout << iERROR << "Error on renaming file " << filename
00133 << " to " << backup << ": " << sys_err_msg << "\n" << endi;
00134 fflush(stdout);
00135 // char errmsg[256];
00136 // sprintf(errmsg, "Error on renaming file %s to %s",filename,backup);
00137 // NAMD_err(errmsg);
00138 }
00139 delete [] backup;
00140 }
00141 }
|
|
|
|
|
Definition at line 88 of file common.C. Referenced by Molecule::build_extra_bonds(), getExtraBonds(), Controller::outputExtendedSystem(), PDB::PDB(), and PDB::write(). 00090 {
00091 char *sys_err_msg = strerror(errno);
00092 if ( ! sys_err_msg ) sys_err_msg = "(unknown error)";
00093 char *new_err_msg = new char[strlen(err_msg) + 20 + strlen(sys_err_msg)];
00094 sprintf(new_err_msg,"FATAL ERROR: %s: %s\n",err_msg, sys_err_msg);
00095 CkPrintf(new_err_msg);
00096 fflush(stdout);
00097 CmiAbort(new_err_msg);
00098 delete [] new_err_msg;
00099 }
|
|
|
Definition at line 62 of file common.C. Referenced by GlobalMasterIMD::get_vmd_forces(). 00064 {
00065 char *new_err_msg = new char[strlen(err_msg) + 20];
00066 sprintf(new_err_msg,"EXITING: %s\n",err_msg);
00067 CkPrintf(new_err_msg);
00068 fflush(stdout);
00069 CmiAbort(new_err_msg);
00070 delete [] new_err_msg;
00071 }
|
|
|
Copyright (c) 1995, 1996, 1997, 1998, 1999, 2000 by The Board of Trustees of the University of Illinois. All rights reserved. Definition at line 48 of file common.C. 00048 {
00049 char *rs;
00050
00051 if(!s)
00052 return NULL;
00053
00054 rs = new char[strlen(s) + 1];
00055 strcpy(rs,s);
00056
00057 return rs;
00058 }
|
|
||||||||||||||||
|
Definition at line 144 of file common.C. References NAMD_bug(), and NAMD_die(). 00144 {
00145 while ( count ) {
00146 #if defined(WIN32) && !defined(__CYGWIN__)
00147 long retval = _write(fd,buf,count);
00148 #else
00149 ssize_t retval = write(fd,buf,count);
00150 #endif
00151 if ( retval < 0 ) NAMD_die(strerror(errno));
00152 if ( retval > count ) NAMD_bug("extra bytes written in NAMD_write()");
00153 buf += retval;
00154 count -= retval;
00155 }
00156 }
|
1.3.9.1