chromium/third_party/nasm/nasmlib/file.c

/* ----------------------------------------------------------------------- *
 *
 *   Copyright 1996-2017 The NASM Authors - All Rights Reserved
 *   See the file AUTHORS included with the NASM distribution for
 *   the specific copyright holders.
 *
 *   Redistribution and use in source and binary forms, with or without
 *   modification, are permitted provided that the following
 *   conditions are met:
 *
 *   * Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *   * Redistributions in binary form must reproduce the above
 *     copyright notice, this list of conditions and the following
 *     disclaimer in the documentation and/or other materials provided
 *     with the distribution.
 *
 *     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
 *     CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
 *     INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 *     MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 *     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 *     CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 *     SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 *     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 *     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 *     HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 *     CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 *     OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 *     EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * ----------------------------------------------------------------------- */

#include "file.h"

void nasm_read(void *ptr, size_t size, FILE *f)
{}

void nasm_write(const void *ptr, size_t size, FILE *f)
{}

void fwriteint16_t(uint16_t data, FILE * fp)
{}

void fwriteint32_t(uint32_t data, FILE * fp)
{}

void fwriteint64_t(uint64_t data, FILE * fp)
{}

void fwriteaddr(uint64_t data, int size, FILE * fp)
{}

void fwritezero(off_t bytes, FILE *fp)
{}

#ifdef _WIN32

/*
 * On Windows, we want to use _wfopen(), as fopen() has a much smaller limit
 * on the path length that it supports.
 *
 * Previously we tried to prefix the path name with \\?\ in order to
 * let the Windows kernel know that we are not limited to PATH_MAX
 * characters, but it breaks relative paths among other things, and
 * apparently Windows 10 contains a registry option to override this
 * limit anyway. One day maybe they will even implement UTF-8 as byte
 * characters so we can use the standard file API even on this OS.
 */

os_filename os_mangle_filename(const char *filename)
{
    mbstate_t ps;
    size_t wclen;
    wchar_t *buf;
    const char *p;

    /*
     * Note: mbsrtowcs() return (size_t)-1 on error, otherwise
     * the length of the string *without* final NUL in wchar_t
     * units. Thus we add 1 for the final NUL; the error value
     * now becomes 0.
     */
    memset(&ps, 0, sizeof ps);  /* Begin in the initial state */
    p = filename;
    wclen = mbsrtowcs(NULL, &p, 0, &ps) + 1;
    if (!wclen)
        return NULL;

    buf = nasm_malloc(wclen * sizeof(wchar_t));

    memset(&ps, 0, sizeof ps);  /* Begin in the initial state */
    p = filename;
    if (mbsrtowcs(buf, &p, wclen, &ps) + 1 != wclen || p) {
        nasm_free(buf);
        return NULL;
    }

    return buf;
}

#endif

void nasm_set_binary_mode(FILE *f)
{}

FILE *nasm_open_read(const char *filename, enum file_flags flags)
{}

FILE *nasm_open_write(const char *filename, enum file_flags flags)
{}

/* The appropriate "rb" strings for os_fopen() */
static const os_fopenflag fopenflags_rb[3] =;

/*
 * Report the existence of a file
 */
bool nasm_file_exists(const char *filename)
{}

/*
 * Report the file size of an open file.  This MAY move the file pointer.
 */
off_t nasm_file_size(FILE *f)
{}

/*
 * Report file size given pathname
 */
off_t nasm_file_size_by_path(const char *pathname)
{}

/*
 * Report the timestamp on a file, returns true if successful
 */
bool nasm_file_time(time_t *t, const char *pathname)
{}