all repos — mgba @ e94744d8c761139a6246ae48e9723825c5bd28f7

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	ssize_t bytesRead = 0;
10	while (bytesRead < size - 1) {
11		ssize_t newRead = vf->read(vf, &buffer[bytesRead], 1);
12		if (newRead <= 0) {
13			break;
14		}
15		bytesRead += newRead;
16		if (buffer[bytesRead] == '\n') {
17			break;
18		}
19	}
20	buffer[bytesRead] = '\0';
21	return bytesRead;
22}
23
24ssize_t VFileWrite32LE(struct VFile* vf, int32_t word) {
25	uint32_t leword;
26	STORE_32LE(word, 0, &leword);
27	return vf->write(vf, &leword, 4);
28}
29
30ssize_t VFileWrite16LE(struct VFile* vf, int16_t hword) {
31	uint16_t lehword;
32	STORE_16LE(hword, 0, &lehword);
33	return vf->write(vf, &lehword, 2);
34}
35
36ssize_t VFileRead32LE(struct VFile* vf, void* word) {
37	uint32_t leword;
38	ssize_t r = vf->read(vf, &leword, 4);
39	if (r == 4) {
40		STORE_32LE(leword, 0, word);
41	}
42	return r;
43}
44
45ssize_t VFileRead16LE(struct VFile* vf, void* hword) {
46	uint16_t lehword;
47	ssize_t r = vf->read(vf, &lehword, 2);
48	if (r == 2) {
49		STORE_16LE(lehword, 0, hword);
50	}
51	return r;
52}