|
|
1.1 root 1: /* lib.c
2: * tag: simple function library
3: *
4: * Copyright (C) 2003 Stefan Reinauer
5: *
6: * See the file "COPYING" for further information about
7: * the copyright and warranty status of this work.
8: */
9:
10: #include "config.h"
11: #include "asm/types.h"
12: #include <stdarg.h>
13: #include "libc/stdlib.h"
14: #include "libc/vsprintf.h"
15: #include "kernel/kernel.h"
16:
17: /* Format a string and print it on the screen, just like the libc
18: * function printf.
19: */
20: int printk( const char *fmt, ... )
21: {
22: char *p, buf[512];
23: va_list args;
24: int i;
25:
26: va_start(args, fmt);
27: i = vsnprintf(buf, sizeof(buf), fmt, args);
28: va_end(args);
29:
30: for( p=buf; *p; p++ )
31: putchar(*p);
32: return i;
33: }
34:
35: // dumb quick memory allocator until we get a decent thing here.
36:
37: #define MEMSIZE 128*1024
38: static char memory[MEMSIZE];
39: static void *memptr=memory;
40: static int memsize=MEMSIZE;
41:
42: void *malloc(int size)
43: {
44: void *ret=(void *)0;
45: if(memsize>=size) {
46: memsize-=size;
47: ret=memptr;
48: memptr = (void *)((unsigned long)memptr + size);
49: }
50: return ret;
51: }
52:
53: void free(void *ptr)
54: {
55: /* Nothing yet */
56: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.