Files
test2/source/blender/blenlib/intern/filereader_file.c
Sergey Sharybin c1bc70b711 Cleanup: Add a copyright notice to files and use SPDX format
A lot of files were missing copyright field in the header and
the Blender Foundation contributed to them in a sense of bug
fixing and general maintenance.

This change makes it explicit that those files are at least
partially copyrighted by the Blender Foundation.

Note that this does not make it so the Blender Foundation is
the only holder of the copyright in those files, and developers
who do not have a signed contract with the foundation still
hold the copyright as well.

Another aspect of this change is using SPDX format for the
header. We already used it for the license specification,
and now we state it for the copyright as well, following the
FAQ:

    https://reuse.software/faq/
2023-05-31 16:19:06 +02:00

66 lines
1.4 KiB
C

/* SPDX-FileCopyrightText: 2004-2021 Blender Foundation
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup bli
*/
#ifndef WIN32
# include <unistd.h> /* for read close */
#else
# include "BLI_winstuff.h"
# include "winsock2.h"
# include <io.h> /* for open close read */
#endif
#include "BLI_blenlib.h"
#include "BLI_filereader.h"
#include "MEM_guardedalloc.h"
typedef struct {
FileReader reader;
int filedes;
} RawFileReader;
static ssize_t file_read(FileReader *reader, void *buffer, size_t size)
{
RawFileReader *rawfile = (RawFileReader *)reader;
ssize_t readsize = read(rawfile->filedes, buffer, size);
if (readsize >= 0) {
rawfile->reader.offset += readsize;
}
return readsize;
}
static off64_t file_seek(FileReader *reader, off64_t offset, int whence)
{
RawFileReader *rawfile = (RawFileReader *)reader;
rawfile->reader.offset = BLI_lseek(rawfile->filedes, offset, whence);
return rawfile->reader.offset;
}
static void file_close(FileReader *reader)
{
RawFileReader *rawfile = (RawFileReader *)reader;
close(rawfile->filedes);
MEM_freeN(rawfile);
}
FileReader *BLI_filereader_new_file(int filedes)
{
RawFileReader *rawfile = MEM_callocN(sizeof(RawFileReader), __func__);
rawfile->filedes = filedes;
rawfile->reader.read = file_read;
rawfile->reader.seek = file_seek;
rawfile->reader.close = file_close;
return (FileReader *)rawfile;
}