blob: 9d90b5b99e94398f5d11afbbb9b9f389de8b7619 (
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
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
69
70
71
72
73
|
/* -*- c -*- ------------------------------------------------------------- *
*
* Copyright 2004 Murali Krishnan Ganapathy - All Rights Reserved
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, Inc., 53 Temple Place Ste 330,
* Bostom MA 02111-1307, USA; either version 2 of the License, or
* (at your option) any later version; incorporated herein by reference.
*
* ----------------------------------------------------------------------- */
#include "string.h"
/* String routines */
void *memset(void *buf, int chr, unsigned int len)
{
asm("cld ; rep ; stosb" : "+D" (buf), "+c" (len) : "a" (chr));
return buf;
}
char *strcpy(char *dst, const char *src)
{
char *r = dst;
char c;
do {
c = *src++;
*dst++ = c;
} while ( c );
return r;
}
char *strcat(char *dst, const char * src)
{
char *r = dst;
while (*dst++); // Find end of string
dst--;
while (*src) *dst++ = *src++; // Append
*dst = '\0'; // Terminate string
return r;
}
void dstrcpy(char *dst, const char *src) // DOS strcpy: Make it $ terminated and null terminated
{
while ( *src )
*dst++ = *src++;
*dst++ = '$';
*dst = '\0';
}
int strcmp(const char *a, const char*b)
{
while (*a)
{
if (*a < *b) return -1;
if (*a++ > *b++) return 1;
}
if (*b) return 1; else return 0;
}
int strlen(const char *a)
{
int ans = 0;
while (*a++) ans++;
return ans;
}
|