-
Notifications
You must be signed in to change notification settings - Fork 4
/
upse_util.c
68 lines (51 loc) · 1.19 KB
/
upse_util.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
* UPSE: the unix playstation sound emulator.
*
* Filename: upse_util.c
* Purpose: libupse: utility functions
*
* Copyright (c) 2007 William Pitcock <nenolod@sacredspiral.co.uk>
*
* UPSE is free software, released under the GNU General Public License,
* version 2.
*
* A copy of the GNU General Public License, version 2, is included in
* the UPSE source kit as COPYING.
*
* UPSE is offered without any warranty of any kind, explicit or implicit.
*/
#define _ISOC99_SOURCE
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include "upse-internal.h"
#include "upse.h"
#include "upse-string.h"
float
upse_strtof(const char *value)
{
float val;
_ENTER;
val = atof(value);
_LEAVE;
return val;
}
u8 *
upse_get_buffer(void *fp, const upse_iofuncs_t *funcs, u32 *len_)
{
int len, pos;
u8 *buf;
_ENTER;
pos = funcs->tell_impl(fp);
funcs->seek_impl(fp, 0, SEEK_END);
len = funcs->tell_impl(fp);
funcs->seek_impl(fp, 0, SEEK_SET);
buf = calloc(sizeof(u8), len);
funcs->read_impl(buf, len, 1, fp);
funcs->seek_impl(fp, pos, SEEK_SET);
if (len_ != NULL)
*len_ = len;
_LEAVE;
return buf;
}