all repos — mgba @ a992fcd3d1bc0e20b478b047301e7c11badfe572

mGBA Game Boy Advance Emulator

src/util/vfs.c (view raw)

 1/* Copyright (c) 2013-2015 Jeffrey Pfau
 2 *
 3 * This Source Code Form is subject to the terms of the Mozilla Public
 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 6#include "vfs.h"
 7
 8ssize_t VFileReadline(struct VFile* vf, char* buffer, size_t size) {
 9	size_t bytesRead = 0;
10	while (bytesRead < size - 1) {
11		size_t newRead = vf->read(vf, &buffer[bytesRead], 1);
12		bytesRead += newRead;
13		if (!newRead || buffer[bytesRead] == '\n') {
14			break;
15		}
16	}
17	return buffer[bytesRead] = '\0';
18}
19
20ssize_t VFileWrite32LE(struct VFile* vf, int32_t word) {
21	uint32_t leword;
22	STORE_32LE(word, 0, &leword);
23	return vf->write(vf, &leword, 4);
24}
25
26ssize_t VFileWrite16LE(struct VFile* vf, int16_t hword) {
27	uint16_t lehword;
28	STORE_16LE(hword, 0, &lehword);
29	return vf->write(vf, &lehword, 2);
30}
31
32ssize_t VFileRead32LE(struct VFile* vf, void* word) {
33	uint32_t leword;
34	ssize_t r = vf->read(vf, &leword, 4);
35	if (r == 4) {
36		STORE_32LE(leword, 0, word);
37	}
38	return r;
39}
40
41ssize_t VFileRead16LE(struct VFile* vf, void* hword) {
42	uint16_t lehword;
43	ssize_t r = vf->read(vf, &lehword, 2);
44	if (r == 2) {
45		STORE_16LE(lehword, 0, hword);
46	}
47	return r;
48}