mescc: Add strcpy.

* libc/include/string.h (strcpy): Declare.
* libc/mlibc.c (strcpy): New function.
* module/mes/libc.mes (strcpy): New function.
  (libc): Add it.
* scaffold/t.c (string_test): Test it.
This commit is contained in:
Jan Nieuwenhuizen 2017-05-08 21:15:53 +02:00
parent 5d0202bbf7
commit ae7a42671a
5 changed files with 41 additions and 1 deletions

View file

@ -36,6 +36,7 @@ typedef long size_t;
size_t strlen (char const*);
int strcmp (char const*, char const*);
int strncmp (char const*, char const*, size_t);
char *strcpy (char *dest, char const *src);
#endif // ! (__GNUC__ && POSIX)
#endif // __STRING_H

View file

@ -210,6 +210,15 @@ strcmp (char const* a, char const* b)
return *a - *b;
}
char *
strcpy (char *dest, char const *src)
{
char *p = dest;
while (*src) *p++ = *src++;
*p = 0;
return dest;
}
int
eputs (char const* s)
{

View file

@ -1971,6 +1971,10 @@
((decl (decl-spec-list (type-spec (fixed-type ,type)) (type-qual ,qual)) (init-declr-list (init-declr (ptr-declr (pointer) (ftn-declr (ident ,name) (param-list . ,param-list))))))
info)
;; char *strcpy ();
((decl (decl-spec-list (type-spec (fixed-type ,type))) (init-declr-list (init-declr (ptr-declr (pointer) (ftn-declr (ident ,name) (param-list . ,param-list))))))
info)
;; printf (char const* format, ...)
((decl (decl-spec-list (type-spec (fixed-type ,type))) (init-declr-list (init-declr (ftn-declr (ident ,name) (param-list ,param-list . (ellipsis))))))
info)

View file

@ -214,6 +214,20 @@ strcmp (char const* a, char const* b)
}
" parse-c99))
(define (strcpy)
(format (current-error-port) "parsing: strcpy\n")
(with-input-from-string
"
char *
strcpy (char *dest, char const *src)
{
char *p = dest;
while (*src) *p++ = *src++;
*p = 0;
return dest;
}
" parse-c99))
(define (itoa)
(format (current-error-port) "parsing: itoa\n")
(with-input-from-string
@ -395,6 +409,7 @@ printf (char const* format, int va_args)
fputs
puts
strcmp
strcpy
itoa
isdigit
atoi

View file

@ -567,6 +567,17 @@ struct_test ()
return make_tmps_test (g_cells);
}
int
string_test ()
{
puts ("t: strcpy (buf, \"hallo\")\n");
char buf[10];
strcpy (buf, "hallo");
if (strcmp (buf, "hallo")) return 1;
return struct_test ();
}
void
void_func ()
{
@ -946,7 +957,7 @@ test (char *p)
puts ("void_func ()\n");
void_func ();
return struct_test ();
return string_test ();
}
#endif