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/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++) {
Note: See TracChangeset for help on using the changeset viewer.