extern char * strcpy __P ((char*, const char*));
extern int strcmp __P ((const char*, const char*));
-extern char * strncat __P ((const char*, const char*, size_t));
-extern char * strncpy __P ((const char*, const char*, size_t));
+extern char * strncat __P ((char*, const char*, size_t));
+extern char * strncpy __P ((char*, const char*, size_t));
extern int strncmp __P((const char*, const char*, size_t));
extern int stricmp __P((const char*, const char*));
#define HDIO_GETGEO 0x0101
#define HDIO_GET_IDENTITY 0x0102 /* Not yet implemented anywhere */
-extern int _exit(int code);
+struct times;
+struct utsname;
+struct tms;
+
+extern void _exit(int code);
extern int open(const char *path, int flags, ...);
extern int close(int fd);
extern int creat(const char *path, mode_t mode);
extern time_t time(time_t *t);
extern int stime(const time_t *t);
extern int times(struct tms *tms);
-extern int utime(const char *filename, const struct utimbuf *utim);
+//extern int utime(const char *filename, const struct utimbuf *utim);
extern int uname(struct utsname *buf);
extern int profil(unsigned short *bufbase, size_t bufsize, unsigned long offset,
unsigned int scale);
#include <string.h>\r
\r
/********************** Function memchr ************************************/ \r
-void *memchr(void *str, int c, size_t l) \r
+void *memchr(const void *str, int c, size_t l) \r
{
- register char *p = (char *) str;
+ register const char *p = str;
\r
while (l-- != 0) {
if (*p == c)
- return p;
+ return (void*) p;
p++;
}
return NULL;
-/* memcmp.c\r
- * Copyright (C) 1995,1996 Robert de Bath <rdebath@cix.compulink.co.uk>\r
- * This file is part of the Linux-8086 C library and is distributed\r
- * under the GNU Library General Public License.\r
- *\r
- * Z80 rewrite from UMZIX\r
+/*\r
+ * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.\r
+ * This file is licensed under the terms of the MIT open source license.\r
*/\r
- \r
-#include <stdlib.h>\r
\r
-/********************** Function memcmp ************************************/\r
-int memcmp(void *s, void *d, size_t l) __naked\r
-{\r
-__asm\r
-\r
- push ix\r
- ld ix,#0\r
- add ix,sp\r
+#include <string.h>\r
\r
- ; d = BC, s=HL, l=DE\r
- \r
- ld l, 4(ix)\r
- ld h, 5(ix)\r
- ld c, 6(ix)\r
- ld b, 7(ix)\r
- ld e, 8(ix)\r
- ld d, 9(ix)\r
- push bc\r
- pop iy ; IY=d\r
- ld bc,#0x0000 ; char1, char2\r
-l_1: \r
- ld a,(hl)\r
- ld b,a\r
- ld a,(iy) ; char1 != char 2 ?\r
- ld c,a\r
- cp b\r
- jr nz,l_2\r
- inc hl ; s++\r
- inc iy ; d++\r
- dec de ; l--\r
- ld a,d\r
- or e\r
- jp nz,l_1 ; l != 0, continue\r
-l_2: \r
- ld a,c ; char1 - char2\r
- ld e,a\r
- rla\r
- sbc a,a\r
- ld d,a\r
- ld a,b\r
- ld l,b\r
- rla\r
- sbc a,a\r
- ld h,a\r
- or a\r
- sbc hl,de\r
+int\r
+memcmp(const void *s1, const void *s2, size_t n)\r
+{\r
+ register const unsigned char *p1 = s1, *p2 = s2;\r
\r
- pop ix\r
- ret\r
-__endasm;\r
+ if (n) {\r
+ n++;\r
+ while (--n > 0) {\r
+ if (*p1++ == *p2++) continue;\r
+ return *--p1 - *--p2;\r
+ }\r
+ }\r
+ return 0;\r
}\r
-#include <string.h>
+/*
+ * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
+ * This file is licensed under the terms of the MIT open source license.
+ */
-/* Z80 rewrite from UMZIX */
+#include <string.h>
-void *memcpy(void *dst, void *src, size_t count) __naked
+void *
+memcpy(void *s1, const void *s2, register size_t n)
{
-__asm
- push ix
- ld ix,#0
- add ix,sp
-
- ld e, 4(ix)
- ld d, 5(ix)
- ld l, 6(ix)
- ld h, 7(ix)
- ld c, 8(ix)
- ld b, 9(ix)
- push de
- ld a,b
- or c
- jr z,_skip
+ register char *p1 = s1;
+ register const char *p2 = s2;
- ldir
-_skip:
- pop hl
-
- pop ix
- ret
-__endasm;
+ if (n) {
+ n++;
+ while (--n > 0) {
+ *p1++ = *p2++;
+ }
+ }
+ return s1;
}
--- /dev/null
+/*
+ * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
+ * This file is licensed under the terms of the MIT open source license.
+ */
+
+#include <string.h>
+
+void *
+memmove(void *s1, const void *s2, register size_t n)
+{
+ register char *p1 = s1;
+ register const char *p2 = s2;
+
+ if (n>0) {
+ if (p2 <= p1 && p2 + n > p1) {
+ /* overlap, copy backwards */
+ p1 += n;
+ p2 += n;
+ n++;
+ while (--n > 0) {
+ *--p1 = *--p2;
+ }
+ } else {
+ n++;
+ while (--n > 0) {
+ *p1++ = *p2++;
+ }
+ }
+ }
+ return s1;
+}
-/* memset.c\r
- * Copyright (C) 1995,1996 Robert de Bath <rdebath@cix.compulink.co.uk>\r
- * This file is part of the Linux-8086 C library and is distributed\r
- * under the GNU Library General Public License.\r
- *\r
- * Z80 rewrite from UMZIX\r
+/*\r
+ * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.\r
+ * This file is licensed under the terms of the MIT open source license.\r
*/\r
+#include <string.h>\r
\r
-#include <stdlib.h>\r
-\r
-/********************** Function memset ************************************/\r
-void *memset(void *str, int c, size_t l) __naked\r
+void *\r
+memset(void *s, register int c, register size_t n)\r
{\r
-__asm\r
- push ix\r
- ld ix,#0\r
- add ix,sp\r
+ register char *s1 = s;\r
\r
- ld l, 4(ix)\r
- ld h, 5(ix)\r
- ld d, 6(ix)\r
- ld c, 8(ix)\r
- ld b, 9(ix)\r
- ld a,b\r
- or c ; l=0? so return\r
- jr z,_retw\r
- ld a,d\r
- ld (hl),a ; fill first byte\r
- ld d,h\r
- ld e,l\r
- inc de ; DE=str+1\r
- dec bc\r
- ld a,b ; l=1? so return\r
- or c\r
- jr z,_retw\r
- push hl\r
- ldir\r
- pop hl\r
- \r
-_retw:\r
- pop ix\r
- ret\r
-__endasm;\r
+ if (n>0) {\r
+ n++;\r
+ while (--n > 0) {\r
+ *s1++ = c;\r
+ }\r
+ }\r
+ return s;\r
}\r
--- /dev/null
+#include <stdio.h>
+
+/* Some compilers will emit calls to this function, even though it's strictly
+ * a macro; so we have to have a real function version of it. */
+
+int (putchar)(int c)
+{
+ return putchar(c);
+}
+
#include <string.h>\r
\r
/********************** Function strcat ************************************/ \r
-char *strcat(char *d, char *s) \r
+char *strcat(char *d, const char *s) \r
{
strcpy(d + strlen(d), s);
return d;
\r
/* FIXME: asm version ?? */ \r
/********************** Function strchr ************************************/ \r
-char *strchr(char *s, int c) \r
+char *strchr(const char *s, int c) \r
{
register char ch;
\r
#include <string.h>\r
\r
/********************** Function strcmp ************************************/ \r
-int strcmp(char *d, char *s) \r
+int strcmp(const char *d, const char *s) \r
{
register char *s1 = (char *) d, *s2 = (char *) s, c1, c2;
\r
#include <string.h>\r
\r
/********************** Function strcpy ************************************/ \r
-char *strcpy(char *d, char *s) \r
+char *strcpy(char *d, const char *s) \r
{
return memcpy(d, s, strlen(s) + 1);
}
#include <string.h>
-size_t strcspn(char *string, char *set)
+size_t strcspn(const char *string, const char *set)
/*
* Return the length of the sub-string of <string> that consists
* entirely of characters not found in <set>. The terminating '\0'
* character if <string> is in <set>, 0 is returned.
*/
{
- register char *setptr;
+ register const char *setptr;
char *start;
start = string;
#include <string.h>
/********************** Function strlen ************************************/
-size_t strlen(char *str) __naked
+size_t strlen(const char *str)
{
-__asm
- pop bc
- pop hl
- push hl
- push bc
- xor a, a
- ld b, a
- ld c, a
- cpir
- ld hl, #-1
- sbc hl, bc ; C flag still cleared from xor above.
- ret
-__endasm;
+ const char* start = str;
+ while (*str++)
+ ;
+ return str - start;
}
#include <string.h>\r
\r
/********************** Function strncat ************************************/ \r
-char *strncat(char *d, char *s, size_t l) \r
+char *strncat(char *d, const char *s, size_t l) \r
{
register char *s1 = d + strlen(d), *s2 = memchr(s, 0, l);
\r
--- /dev/null
+/*
+ * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
+ * This file is licensed under the terms of the MIT open source license.
+ */
+
+#include <string.h>
+
+int
+strncmp(register const char *s1, register const char *s2, register size_t n)
+{
+ if (n) {
+ do {
+ if (*s1 != *s2++)
+ break;
+ if (*s1++ == '\0')
+ return 0;
+ } while (--n > 0);
+ if (n > 0) {
+ if (*s1 == '\0') return -1;
+ if (*--s2 == '\0') return 1;
+ return (unsigned char) *s1 - (unsigned char) *s2;
+ }
+ }
+ return 0;
+}
#include <string.h>\r
\r
/********************** Function strncpy ************************************/ \r
-char *strncpy(char *d, char *s, size_t l) \r
+char *strncpy(char *d, const char *s, size_t l) \r
{
- register char *s1 = d, *s2 = s;\r
+ register char *s1 = d;
+ register const char *s2 = s;\r
\r
while (l) {
l--;
#include <string.h>\r
\r
/********************** Function strrchr ************************************/ \r
-char *strrchr(char *s, int c) \r
+char *strrchr(const char *s, int c) \r
{
- register char *p = s + strlen(s);
+ register const char *p = s + strlen(s);
\r
/* For null it's just like strlen */ \r
if (c == '\0')