formatting, strncpy
This commit is contained in:
parent
3981746d2a
commit
f10dd4afce
2
Makefile
2
Makefile
|
@ -4,7 +4,7 @@ CFLAGS=-Ilib83 -c -mz80 --std-sdcc2x --no-std-crt0 --reserve-regs-iy --opt-code-
|
|||
|
||||
OBJS=_crt0.rel clrscr.rel putchar.rel puts.rel exit.rel gotoxy.rel __assert_fail.rel \
|
||||
getchar.rel put_int.rel ctype.rel memcpy.rel memset.rel memmove.rel memcmp.rel \
|
||||
strcpy.rel strlen.rel \
|
||||
strcpy.rel strlen.rel strncpy.rel \
|
||||
main.rel
|
||||
|
||||
.PHONY: all clean try
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
extern void main();
|
||||
|
||||
void AppHeader() {
|
||||
void _start() {
|
||||
__asm
|
||||
.db 0x80, 0x0F
|
||||
.db 0, 0, 0, 0
|
||||
|
|
|
@ -4,6 +4,6 @@
|
|||
|
||||
#define assert(expr) ((expr) ? (void) (0) : __assert_fail(#expr, __FILE__, __LINE__, __func__))
|
||||
|
||||
extern void __assert_fail(const char *__assertion, const char *__file, unsigned int __line, const char *__function);
|
||||
extern void __assert_fail(const char * __assertion, const char * __file, unsigned int __line, const char * __function);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -4,10 +4,10 @@
|
|||
int8_t memcmp(void * buf1, void * buf2, size_t count) {
|
||||
if (!count) return 0;
|
||||
|
||||
while (--count && *(unsigned char*)buf1 == *(unsigned char*)buf2) {
|
||||
while (--count && *(unsigned char *)buf1 == *(unsigned char *)buf2) {
|
||||
buf1 = 1 + (unsigned char *)buf1; buf2 = 1 + (unsigned char *)buf2;
|
||||
}
|
||||
|
||||
return *(char*)buf1 - *(char*)buf2;
|
||||
return *(char *)buf1 - *(char *)buf2;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#ifndef _STDDEF_H
|
||||
#define _STDDEF_H
|
||||
|
||||
#define NULL ((void *)0)
|
||||
#define NULL ((void *) 0)
|
||||
|
||||
typedef unsigned char uint8_t;
|
||||
typedef unsigned short uint16_t;
|
||||
|
|
|
@ -4,17 +4,17 @@
|
|||
|
||||
#include <stddef.h>
|
||||
|
||||
extern void *memcpy(void *dest, const void *src, size_t n);
|
||||
extern void *memset(void *s, unsigned char c, size_t n);
|
||||
extern void *memmove(void *dest, const void *src, size_t n);
|
||||
extern int8_t memcmp(const void *s1, const void *s2, size_t n);
|
||||
extern void * memcpy(void * dest, const void * src, size_t n);
|
||||
extern void * memset(void * s, unsigned char c, size_t n);
|
||||
extern void * memmove(void * dest, const void * src, size_t n);
|
||||
extern int8_t memcmp(const void * s1, const void * s2, size_t n);
|
||||
|
||||
extern char *strcpy(char *dest, const char *src);
|
||||
extern char *strncpy(char *dest, const char *src, size_t n);
|
||||
extern size_t strlen(const char *s);
|
||||
extern int8_t strcmp(const char *s1, const char *s2);
|
||||
extern int8_t strncmp(const char *s1, const char *s2, size_t n);
|
||||
extern char * strcat(char *dest, const char *src);
|
||||
extern char * strcpy(char * dest, const char * src);
|
||||
extern char * strncpy(char * dest, const char * src, size_t n);
|
||||
extern size_t strlen(const char * s);
|
||||
extern int8_t strcmp(const char * s1, const char * s2);
|
||||
extern int8_t strncmp(const char * s1, const char * s2, size_t n);
|
||||
extern char * strcat(char * dest, const char * src);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
10
lib83/strncpy.c
Normal file
10
lib83/strncpy.c
Normal file
|
@ -0,0 +1,10 @@
|
|||
|
||||
#include <string.h>
|
||||
|
||||
char * strncpy(char * d, const char * s, size_t n) {
|
||||
register char * d1 = d;
|
||||
while (n && *s) { n--; *d++ = *s++; }
|
||||
while (n--) *d++ = '\0' ;
|
||||
return d1;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user