summaryrefslogtreecommitdiff
path: root/ulib.c
blob: 004b934209fdb08a86b2e2257e21ab52be95197f (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
#include "types.h"
#include "stat.h"
#include "fcntl.h"
#include "user.h"

int
puts(char *s)
{
  return write(1, s, strlen(s));
}

char*
strcpy(char *s, char *t)
{
	char *os;
	
	os = s;
	while((*s++ = *t++) != 0)
		;
	return os;
}

unsigned int
strlen(char *s)
{
  int n = 0;
  for(n = 0; s[n]; n++)
    ;
  return n;
}

void *
memset(void *dst, int c, unsigned int n)
{
  char *d = (char *) dst;

  while(n-- > 0)
    *d++ = c;

  return dst;
}

char *
gets(char *buf, int max)
{
  int i = 0, cc;
  char c;
  
  while(i+1 < max){
    cc = read(0, &c, 1);
    if(cc < 1)
      break;
    if(c == '\n' || c == '\r')
      break;
    buf[i++] = c;
  }
  buf[i] = '\0';
  return buf;
}

int
stat(char *n, struct stat *st)
{
  int fd;
  int r;

  fd = open(n, O_RDONLY);
  if (fd < 0) return -1;
  r = fstat(fd, st);
  close(fd);
  return r;
}