Ejemplo n.º 1
0
bool ini_write_string_section(const char *p_file, const char *p_section, 
                              const char *p_template, const char *p_value)
{
  int ret;

  FFILE f_orig(NULL, p_file, "r", FALSE);
  if (!f_orig)
    return(FALSE);
    
  FFILE f_new(tmpfile());
  if (!f_new)
    return(FALSE);
  
  ret = file_copy(f_orig, f_new);
  if(!ret) {
    fclose(f_orig);
    fclose(f_new);
    return(FALSE);  
  }
    
  f_orig.close();
  
  if(f_orig.open(NULL, p_file, "w", FALSE)) {
    ret = ini_write_string_section(f_new, f_orig, p_section, p_template, p_value);
    fclose(f_orig);
  }
  
  fclose(f_new);
  
  return (ret);
}
Ejemplo n.º 2
0
int main(int argc, char* argv[])
{

  try 
  {
    // create a new empty file
    saga::filesystem::file f_orig("/tmp/hello.txt", saga::filesystem::Create);

    // write the string "Hello, World!" to the file
    char txt[] = "Hello, World!";
    f_orig.write(saga::buffer(txt, sizeof(txt)));
    
    // copy the file
    f_orig.copy("/tmp/hello_copy.txt");
     
    // open the copy and read the content
    saga::filesystem::file f_copy("/tmp/hello_copy.txt");
    
    saga::mutable_buffer buf (1024*64);
    while (true) 
    {
      // read a chunk into the buffer
      if ( f_copy.read (buf, 1024*64) ) {
        std::cout << (char*) (buf.get_data ());
      }
      else break;
    }
    
    // delete both files
    f_orig.remove();
    f_copy.remove();
  } 
  catch(saga::exception const & e) {
    std::cerr << e.what() << std::endl;
  }
  return 0;
}