2006-08-14 03:00:13 +00:00
|
|
|
#include "types.h"
|
|
|
|
#include "stat.h"
|
|
|
|
#include "fcntl.h"
|
2006-07-16 15:36:31 +00:00
|
|
|
#include "user.h"
|
|
|
|
|
2006-06-27 14:35:53 +00:00
|
|
|
int
|
|
|
|
puts(char *s)
|
2006-07-16 15:36:31 +00:00
|
|
|
{
|
2006-08-11 13:55:18 +00:00
|
|
|
return write(1, s, strlen(s));
|
2006-06-27 14:35:53 +00:00
|
|
|
}
|
|
|
|
|
2006-07-16 16:00:03 +00:00
|
|
|
char*
|
|
|
|
strcpy(char *s, char *t)
|
|
|
|
{
|
2006-09-06 17:04:06 +00:00
|
|
|
char *os;
|
2006-09-06 17:27:19 +00:00
|
|
|
|
2006-09-06 17:04:06 +00:00
|
|
|
os = s;
|
|
|
|
while((*s++ = *t++) != 0)
|
|
|
|
;
|
|
|
|
return os;
|
2006-07-16 16:00:03 +00:00
|
|
|
}
|
2006-08-11 13:55:18 +00:00
|
|
|
|
2006-08-23 01:09:24 +00:00
|
|
|
int
|
|
|
|
strcmp(const char *p, const char *q)
|
|
|
|
{
|
2006-09-06 17:27:19 +00:00
|
|
|
while(*p && *p == *q)
|
2006-09-06 17:04:06 +00:00
|
|
|
p++, q++;
|
|
|
|
return (int) ((unsigned char) *p - (unsigned char) *q);
|
2006-08-23 01:09:24 +00:00
|
|
|
}
|
|
|
|
|
2006-08-11 13:55:18 +00:00
|
|
|
unsigned int
|
|
|
|
strlen(char *s)
|
|
|
|
{
|
|
|
|
int n = 0;
|
|
|
|
for(n = 0; s[n]; n++)
|
|
|
|
;
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2006-09-06 17:04:06 +00:00
|
|
|
void*
|
2006-08-12 11:38:57 +00:00
|
|
|
memset(void *dst, int c, unsigned int n)
|
|
|
|
{
|
2006-09-06 17:27:19 +00:00
|
|
|
char *d = (char*) dst;
|
2006-08-12 11:38:57 +00:00
|
|
|
|
|
|
|
while(n-- > 0)
|
|
|
|
*d++ = c;
|
|
|
|
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
2006-09-06 17:04:06 +00:00
|
|
|
char*
|
2006-08-23 01:09:24 +00:00
|
|
|
strchr(const char *s, char c)
|
|
|
|
{
|
2006-09-06 17:27:19 +00:00
|
|
|
for(; *s; s++)
|
|
|
|
if(*s == c)
|
|
|
|
return (char*) s;
|
2006-09-06 17:04:06 +00:00
|
|
|
return 0;
|
2006-08-23 01:09:24 +00:00
|
|
|
}
|
|
|
|
|
2006-09-06 17:04:06 +00:00
|
|
|
char*
|
2006-08-11 13:55:18 +00:00
|
|
|
gets(char *buf, int max)
|
|
|
|
{
|
|
|
|
int i = 0, cc;
|
|
|
|
char c;
|
2006-09-06 17:27:19 +00:00
|
|
|
|
2006-08-11 13:55:18 +00:00
|
|
|
while(i+1 < max){
|
|
|
|
cc = read(0, &c, 1);
|
|
|
|
if(cc < 1)
|
|
|
|
break;
|
2007-08-08 08:04:20 +00:00
|
|
|
buf[i++] = c;
|
2006-08-11 13:55:18 +00:00
|
|
|
if(c == '\n' || c == '\r')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
buf[i] = '\0';
|
|
|
|
return buf;
|
|
|
|
}
|
2006-08-14 03:00:13 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
stat(char *n, struct stat *st)
|
|
|
|
{
|
2006-08-14 14:13:52 +00:00
|
|
|
int fd;
|
2006-08-14 03:00:13 +00:00
|
|
|
int r;
|
|
|
|
|
2006-08-14 14:13:52 +00:00
|
|
|
fd = open(n, O_RDONLY);
|
2006-09-06 17:57:47 +00:00
|
|
|
if(fd < 0)
|
|
|
|
return -1;
|
2006-08-14 03:00:13 +00:00
|
|
|
r = fstat(fd, st);
|
|
|
|
close(fd);
|
|
|
|
return r;
|
|
|
|
}
|