Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Android/device/device/google/contexthub/util/common/   (Android Betriebssystem Version 17©)  Datei vom 26.5.2026 mit Größe 1 kB image not shown  

Quelle  file.cpp

  Sprache: C
 

/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


#include "file.h"

#include <fcntl.h>
#include <string.h>
#include <unistd.h>

namespace android {

File::File()
    : mInitCheck(NO_INIT),
      mFd(-1) {
}

File::File(const char *path, const char *mode)
    : mInitCheck(NO_INIT),
      mFd(-1) {
    mInitCheck = setTo(path, mode);
}

File::~File() {
    close();
}

status_t File::initCheck() const {
    return mInitCheck;
}

status_t File::setTo(const char *path, const char *mode) {
    close();

    int modeval = 0;
    if (!strcmp("r", mode)) {
        modeval = O_RDONLY;
    } else if (!strcmp("w", mode)) {
        modeval = O_WRONLY | O_CREAT | O_TRUNC;
    } else if (!strcmp("rw", mode)) {
        modeval = O_RDWR | O_CREAT;
    }

    int filemode = 0;
    if (modeval & O_CREAT) {
        filemode = S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH;
    }

    mFd = open(path, modeval, filemode);

    mInitCheck = (mFd >= 0) ? OK : -errno;

    return mInitCheck;
}

void File::close() {
    if (mFd >= 0) {
        ::close(mFd);
        mFd = -1;
    }

    mInitCheck = NO_INIT;
}

ssize_t File::read(void *data, size_t size) {
    return ::read(mFd, data, size);
}

ssize_t File::write(const void *data, size_t size) {
    return ::write(mFd, data, size);
}

off64_t File::seekTo(off64_t pos, int whence) {
    off64_t new_pos = lseek64(mFd, pos, whence);
    return new_pos < 0 ? -errno : new_pos;
}

}  // namespace android

Messung V0.5 in Prozent
C=91 H=95 G=92

¤ Dauer der Verarbeitung: 0.13 Sekunden  (vorverarbeitet am  2026-06-27) ¤

*© 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.