strlen-c/1

52 lines
758 B
Plaintext
Raw Permalink Normal View History

2024-06-03 20:03:11 +00:00
#include <stdint.h>
char * ptr1 = "jan";
char * ptr2 = "kowalski";
int strlen(char *s)
{
char *p = s;
while (*p != '\0')
p++;
return p - s;
}
void strcpy(char *s, char *t)
{
while (*s++ = *t++);
}
#define ALLOCSIZE 10000
static char allocbuf[ALLOCSIZE];
static char *allocp = allocbuf;
char *alloc(int n)
{
/*
if (n % 4 != 0) {
n += 4 - (n % 4);
}
*/
if (allocbuf + ALLOCSIZE - allocp >= n) {
allocp += n;
return allocp - n;
} else
return 0;
}
int main() {
char * p1 = alloc(strlen(ptr1));
strcpy (p1, ptr1);
asm("nop");
char * p2 = alloc(strlen(ptr2));
strcpy (p2, ptr2);
asm("nop");
return 1;
}