forked from kode54/libupse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
upse_string.c
52 lines (46 loc) · 943 Bytes
/
upse_string.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
/*
* UPSE: the unix playstation sound emulator.
*
* Filename: upse_string.c
* Purpose: libupse: string utility functions
*
* Copyright (c) 2007 William Pitcock <[email protected]>
*
* 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.
*/
#include "upse.h"
#include "upse-string.h"
/*
* fgets() wrapper - inefficient, but it will do.
*/
char *upse_io_fgets(char *s, int n, void *stream, const upse_iofuncs_t * iofuncs)
{
int c;
register char *p;
if (n <= 0)
return NULL;
p = s;
while (--n)
{
if (iofuncs->read_impl(&c, 1, 1, stream) == 0)
{
break;
}
if ((*p++ = c) == '\n')
{
break;
}
}
if (p > s)
{
*p = 0;
return s;
}
return NULL;
}