[go: up one dir, main page]

File: upse_string.c

package info (click to toggle)
upse 0.6.0-1.1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 1,016 kB
  • ctags: 966
  • sloc: ansic: 5,600; sh: 3,479; makefile: 91
file content (52 lines) | stat: -rw-r--r-- 937 bytes parent folder | download | duplicates (5)
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 <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.
 */

#include "upse.h"
#include "upse-string.h"

/*
 * fgets() wrapper - inefficient, but it will do.
 */
char *upse_io_fgets(char *s, int n, void *stream, 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;
}