Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/browser/app/desktop-launcher/   (Firefox Browser Version 153.0.1©)  Datei vom 27.6.2026 mit Größe 1 kB image not shown  

Quelle  file_sink.cpp

  Sprache: C
 

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */


#include "file_sink.h"
#include <iostream>
#include <string>
#include <windows.h>

// Open the download receiver
bool FileSink::open(std::wstring& filename) {
  mFilename.assign(filename);
  // Note: this only succeeds if the filename does not exist.
  fileHandle.own(CreateFileW(filename.c_str(), GENERIC_WRITE,
                             FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr,
                             CREATE_NEW, FILE_ATTRIBUTE_NORMAL, nullptr));
  if (fileHandle.get() == INVALID_HANDLE_VALUE) {
    return false;
  } else {
    return true;
  }
}

// Send data to the download receiver
bool FileSink::accept(char* buf, int bytesToWrite) {
  while (bytesToWrite > 0) {
    DWORD bytesWritten = 0;
    if (!WriteFile(fileHandle, buf, bytesToWrite, &bytesWritten, nullptr)) {
      std::cout << "Failed to write! " << GetLastError() << std::endl;
      return false;  // Some kind of error happened
    }
    bytesToWrite -= bytesWritten;
  }
  return true;
}

bool FileSink::freeze() {
  // Exchange our write-only handle for a read-only one. This allows us to
  // prevent renaming or deleting the file under our nose, while also being
  // able to actually run it.
  HANDLE readOnlyHandle = CreateFileW(
      mFilename.c_str(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
      nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
  if (readOnlyHandle == INVALID_HANDLE_VALUE) {
    return false;
  }

  fileHandle.own(readOnlyHandle);
  return true;
}

Messung V0.5 in Prozent
C=90 H=74 G=82

¤ Dauer der Verarbeitung: 0.11 Sekunden  (vorverarbeitet am  2026-08-26) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.