aboutsummaryrefslogtreecommitdiffstats
path: root/library.cpp
blob: 188429dd06b71009473955bb7310868c2c0fd9d2 (plain)
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
#include <library.hpp>

void strncpy(char *dst, const char *src, int cnt)
{
	int i = 0;
	do {
		dst[i] = src[i];
	} while (++i < cnt && src[i] != 0);
}

int strcpy(char *dst, const char *src)
{
	int i = 0;
	while (*dst && *src)
		*dst++ = *src++, i++;

	return i;
}

char *itoa(int n, int base)
{
	static char buf[16];
	char *p = buf + 16;

	*--p = '\0';
	do {
		*--p = "0123456789abcdef"[n % base];
	} while (n /= base);

	return p;
}