2006-08-14 05:00:13 +02:00
|
|
|
#include "types.h"
|
|
|
|
#include "stat.h"
|
|
|
|
#include "fcntl.h"
|
2006-07-16 17:36:31 +02:00
|
|
|
#include "user.h"
|
2009-03-08 22:38:30 +01:00
|
|
|
#include "x86.h"
|
2006-07-16 17:36:31 +02:00
|
|
|
|
2006-07-16 18:00:03 +02:00
|
|
|
char*
|
|
|
|
strcpy(char *s, char *t)
|
|
|
|
{
|
2006-09-06 19:04:06 +02:00
|
|
|
char *os;
|
2006-09-06 19:27:19 +02:00
|
|
|
|
2006-09-06 19:04:06 +02:00
|
|
|
os = s;
|
|
|
|
while((*s++ = *t++) != 0)
|
|
|
|
;
|
|
|
|
return os;
|
2006-07-16 18:00:03 +02:00
|
|
|
}
|
2006-08-11 15:55:18 +02:00
|
|
|
|
2006-08-23 03:09:24 +02:00
|
|
|
int
|
|
|
|
strcmp(const char *p, const char *q)
|
|
|
|
{
|
2006-09-06 19:27:19 +02:00
|
|
|
while(*p && *p == *q)
|
2006-09-06 19:04:06 +02:00
|
|
|
p++, q++;
|
2007-08-08 11:30:48 +02:00
|
|
|
return (uchar)*p - (uchar)*q;
|
2006-08-23 03:09:24 +02:00
|
|
|
}
|
|
|
|
|
2007-08-08 11:30:48 +02:00
|
|
|
uint
|
2006-08-11 15:55:18 +02:00
|
|
|
strlen(char *s)
|
|
|
|
{
|
2007-08-10 19:17:42 +02:00
|
|
|
int n;
|
|
|
|
|
2006-08-11 15:55:18 +02:00
|
|
|
for(n = 0; s[n]; n++)
|
|
|
|
;
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2006-09-06 19:04:06 +02:00
|
|
|
void*
|
2007-08-08 11:30:48 +02:00
|
|
|
memset(void *dst, int c, uint n)
|
2006-08-12 13:38:57 +02:00
|
|
|
{
|
2009-03-08 22:38:30 +01:00
|
|
|
stosb(dst, c, n);
|
2006-08-12 13:38:57 +02:00
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
2006-09-06 19:04:06 +02:00
|
|
|
char*
|
2006-08-23 03:09:24 +02:00
|
|
|
strchr(const char *s, char c)
|
|
|
|
{
|
2006-09-06 19:27:19 +02:00
|
|
|
for(; *s; s++)
|
|
|
|
if(*s == c)
|
|
|
|
return (char*) s;
|
2006-09-06 19:04:06 +02:00
|
|
|
return 0;
|
2006-08-23 03:09:24 +02:00
|
|
|
}
|
|
|
|
|
2006-09-06 19:04:06 +02:00
|
|
|
char*
|
2006-08-11 15:55:18 +02:00
|
|
|
gets(char *buf, int max)
|
|
|
|
{
|
2007-08-10 19:17:42 +02:00
|
|
|
int i, cc;
|
2006-08-11 15:55:18 +02:00
|
|
|
char c;
|
2006-09-06 19:27:19 +02:00
|
|
|
|
2007-08-10 19:17:42 +02:00
|
|
|
for(i=0; i+1 < max; ){
|
2006-08-11 15:55:18 +02:00
|
|
|
cc = read(0, &c, 1);
|
|
|
|
if(cc < 1)
|
|
|
|
break;
|
2007-08-08 10:04:20 +02:00
|
|
|
buf[i++] = c;
|
2006-08-11 15:55:18 +02:00
|
|
|
if(c == '\n' || c == '\r')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
buf[i] = '\0';
|
|
|
|
return buf;
|
|
|
|
}
|
2006-08-14 05:00:13 +02:00
|
|
|
|
|
|
|
int
|
|
|
|
stat(char *n, struct stat *st)
|
|
|
|
{
|
2006-08-14 16:13:52 +02:00
|
|
|
int fd;
|
2006-08-14 05:00:13 +02:00
|
|
|
int r;
|
|
|
|
|
2006-08-14 16:13:52 +02:00
|
|
|
fd = open(n, O_RDONLY);
|
2006-09-06 19:57:47 +02:00
|
|
|
if(fd < 0)
|
|
|
|
return -1;
|
2006-08-14 05:00:13 +02:00
|
|
|
r = fstat(fd, st);
|
|
|
|
close(fd);
|
|
|
|
return r;
|
|
|
|
}
|
2007-08-08 10:56:09 +02:00
|
|
|
|
|
|
|
int
|
|
|
|
atoi(const char *s)
|
|
|
|
{
|
|
|
|
int n;
|
|
|
|
|
|
|
|
n = 0;
|
|
|
|
while('0' <= *s && *s <= '9')
|
|
|
|
n = n*10 + *s++ - '0';
|
|
|
|
return n;
|
|
|
|
}
|
2007-08-22 08:01:32 +02:00
|
|
|
|
|
|
|
void*
|
|
|
|
memmove(void *vdst, void *vsrc, int n)
|
|
|
|
{
|
|
|
|
char *dst, *src;
|
|
|
|
|
|
|
|
dst = vdst;
|
|
|
|
src = vsrc;
|
|
|
|
while(n-- > 0)
|
|
|
|
*dst++ = *src++;
|
|
|
|
return vdst;
|
|
|
|
}
|