Changeset 3007


Ignore:
Timestamp:
2002-02-27T11:50:16+13:00 (22 years ago)
Author:
jrm21
Message:

Replaced old code to get file descriptors from ofstreams for locking with
c-style open() functions instead. Now works with gcc3.

Location:
trunk/gsdl/src/recpt
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/src/recpt/collectoraction.cpp

    r2908 r3007  
    4545#include "argdb.h"
    4646#include "cgiutils.h"
     47#include <stdio.h>
     48#include <fcntl.h>
    4749
    4850#if !defined (__WIN32__)
     
    581583   
    582584    // now write cfg file back out
    583 #ifdef __WIN32__
    584     ofstream cfg_out (cfgfilec, ios::binary);
    585 #else
    586     ofstream cfg_out (cfgfilec);
     585    int fd=open(cfgfilec, O_WRONLY | O_CREAT | O_TRUNC
     586#if defined(__WIN32__)
     587        | O_BINARY
    587588#endif
    588     if (cfg_out) {
     589        );
     590
     591    if (fd != -1) {
    589592      // lock the file
    590       int fd = GSDL_GET_FILEDESC(cfg_out);
    591593      int lock_val = 1;
    592594      GSDL_LOCK_FILE (fd);
    593595      if (lock_val != 0) {
    594596    logout << "Error: Couldn't lock file " << cfgfilec << "\n";
    595     cfg_out.close();
     597    close(fd);
    596598    message = "tmpfail";
    597599   
     
    601603    vector<text_tarray>::const_iterator end_line = cfgarray.end();
    602604    while (this_line != end_line) {
    603       write_cfg_line (cfg_out, *this_line);
     605      write_cfg_line (fd, *this_line);
    604606      this_line ++;
    605607    }
    606608    GSDL_UNLOCK_FILE (fd);
    607     cfg_out.close();
     609    close(fd);
    608610      }
    609611
     
    633635  // make sure collect.cfg isn't read-only
    634636  _chmod (cfgfilec, _S_IREAD | _S_IWRITE);
    635   ofstream cfg_out (cfgfilec, ios::binary);
    636 #else
    637   ofstream cfg_out (cfgfilec);
    638637#endif
    639  
    640   if (cfg_out) {
     638
     639  int fd=open(cfgfilec, O_WRONLY | O_CREAT | O_TRUNC
     640#if defined(__WIN32__)
     641          | O_BINARY
     642#endif
     643          );
     644
     645  if (fd) {
    641646    // lock the file
    642     int fd = GSDL_GET_FILEDESC(cfg_out);
    643647    int lock_val = 1;
    644648    GSDL_LOCK_FILE (fd);
    645649    if (lock_val != 0) {
    646650      logout << "Error: Couldn't lock file " << cfgfilec << "\n";
    647       cfg_out.close();
     651      close(fd);
    648652      message = "tmpfail";
    649653     
     
    651655     
    652656      outconvertclass text_t2ascii;
    653       cfg_out << text_t2ascii << args["cfgfile"];
     657      text_t2ascii << args["cfgfile"];
     658      size_t buffersize=args["cfgfile"].size();
     659      char *buffer=new char[buffersize];
     660      size_t num_chars;
     661      convertclass::status_t status;
     662      text_t2ascii.convert(buffer, buffersize, num_chars, status);
     663      // ignore status - assume it is "finished" as buffer is big enough
     664      write(fd, buffer, num_chars);
    654665      GSDL_UNLOCK_FILE (fd);
    655       cfg_out.close();
     666      close(fd);
     667      delete buffer;
    656668     
    657669      // now that we've written the file we'll read it back again and
     
    14901502      shortname.clear();
    14911503      int use_words = (num_words <= 6) ? num_words : 6;
    1492       int substr_len = 6 / use_words;
     1504      unsigned int substr_len = 6 / use_words;
    14931505     
    14941506      for (int i = 0; i < use_words; i++) {
  • trunk/gsdl/src/recpt/receptionist.cpp

    r2957 r3007  
    3737#include <assert.h>
    3838#include <time.h>
    39 #include <stdio.h>
     39#include <stdio.h> // for open()
     40#include <fcntl.h> // for open() flags
    4041// following 2 are for printing Last-Modified http header.
    4142#include <sys/stat.h>
     
    695696  char *lfile = filename.getcstr();
    696697
    697   ofstream log (lfile, ios::app);
    698  
    699   if (!log) {
     698  int fd = open(lfile,O_APPEND);
     699 
     700  if (fd == -1) {
    700701    logout << "Error: Couldn't open file " << lfile << "\n";
    701702    delete lfile;
     
    703704  }
    704705
    705   int fd = GSDL_GET_FILEDESC(log);
     706  //int fd = GSDL_GET_FILEDESC(log);
    706707
    707708  // lock_val is set to 0 if file is locked successfully
     
    709710  GSDL_LOCK_FILE (fd);
    710711  if (lock_val == 0) {
    711     log << text_t2utf8 << logstr;
     712    text_t2utf8 << logstr;
     713    char *buffer=new char[logstr.size()];
     714    size_t num_chars;
     715    convertclass::status_t status;
     716    text_t2utf8.convert(buffer, logstr.size(), num_chars, status);
     717    // ignore status - assume it is "finished" as buffer is big enough
     718    write(fd, buffer, num_chars);
    712719    GSDL_UNLOCK_FILE (fd);
     720    delete buffer;
    713721  } else {
    714722    logout << "Error: Couldn't lock file " << lfile << "\n";
    715     log.close();
     723    close(fd);
    716724    delete lfile;
    717725    return false;
    718726  }
    719727
    720   log.close();
     728  close(fd);
    721729       
    722730  delete lfile;
     
    797805    contentout << "Last-Modified: " << asctime(utc_latest);
    798806      }
    799     }
     807    } // end of collection != ""
    800808
    801809    /*
  • trunk/gsdl/src/recpt/statusaction.cpp

    r2939 r3007  
    3232#include "gsdltools.h"
    3333#include <assert.h>
    34 
     34#include <stdio.h>
     35#include <fcntl.h> // for open() stuff
    3536
    3637void statusaction::output_frameset (cgiargsclass &/*args*/, displayclass &disp,
     
    885886  text_t cfgfile = filename_cat(gsdlhome, "etc", "main.cfg");
    886887  char *cfgfilec = cfgfile.getcstr();
    887 #ifdef __WIN32__
    888   ofstream cfg_out (cfgfilec, ios::binary);
    889 #else
    890   ofstream cfg_out (cfgfilec);
     888
     889  int fd=open(cfgfilec, O_WRONLY | O_CREAT | O_TRUNC
     890#if defined(__WIN32__)
     891          | O_BINARY
    891892#endif
    892  
    893   if (cfg_out) {
    894     // lock the file
    895     int fd = GSDL_GET_FILEDESC(cfg_out);
     893          );
     894
     895  if (fd != -1) {
     896
    896897    int lock_val = 1;
    897898    GSDL_LOCK_FILE (fd);
    898899    if (lock_val != 0) {
    899900      logout << "statusaction::change_maincfg: Error: Couldn't lock file " << cfgfilec << "\n";
    900       cfg_out.close();
    901901      textout << outconvert << disp << "_status:changemaincfgfail_";
    902      
     902      close (fd);
    903903    } else {
    904      
    905904      outconvertclass text_t2ascii;
    906       cfg_out << text_t2ascii << args["cfgfile"];
     905      text_t2ascii << args["cfgfile"];
     906      size_t buffersize=args["cfgfile"].size();
     907      char *buffer=new char[buffersize];
     908      size_t num_chars;
     909      convertclass::status_t status;
     910      text_t2ascii.convert(buffer, buffersize, num_chars, status);
     911      // ignore status - assume it is "finished" as buffer is big enough
     912      write(fd, buffer, num_chars);
    907913      GSDL_UNLOCK_FILE (fd);
    908       cfg_out.close();
     914      delete buffer;
     915      close (fd);
    909916      textout << outconvert << disp << "_status:changemaincfgsuccess_";
    910917    }
     
    913920    textout << outconvert << disp << "_status:changemaincfgfail_";
    914921  }
     922  delete cfgfilec;
    915923}
    916924
Note: See TracChangeset for help on using the changeset viewer.