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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.