memcpy in web

This commit is contained in:
Stefano D'Angelo 2024-02-21 09:03:50 +01:00
parent c688a0e209
commit 98e1510955
7 changed files with 29 additions and 19 deletions

View File

@ -21,6 +21,7 @@ LDFLAGS_ALL = \
-Wl,--export=calloc \ -Wl,--export=calloc \
-Wl,--export=free \ -Wl,--export=free \
-Wl,--export=memset \ -Wl,--export=memset \
-Wl,--export=memcpy \
-Wl,--export=processor_new \ -Wl,--export=processor_new \
-Wl,--export=processor_free \ -Wl,--export=processor_free \
-Wl,--export=processor_get_x_buf \ -Wl,--export=processor_get_x_buf \
@ -40,7 +41,7 @@ LDFLAGS_ALL += ${LDFLAGS} ${LDFLAGS_EXTRA}
CXXFLAGS = ${CFLAGS} CXXFLAGS = ${CFLAGS}
CXXFLAGS_ALL = -I${COMMON_DIR}/src -I${DATA_DIR}/src -I${PLUGIN_DIR} --target=wasm32 -flto -fvisibility=hidden ${CXXFLAGS} ${CXXFLAGS_EXTRA} CXXFLAGS_ALL = -I${COMMON_DIR}/src -I${DATA_DIR}/src -I${PLUGIN_DIR} --target=wasm32 -flto -fvisibility=hidden ${CXXFLAGS} ${CXXFLAGS_EXTRA}
C_SRCS = ${COMMON_DIR}/src/processor.c ${COMMON_DIR}/src/walloc.c ${COMMON_DIR}/src/memset.c C_SRCS = ${COMMON_DIR}/src/processor.c ${COMMON_DIR}/src/walloc.c ${COMMON_DIR}/src/string.c
C_OBJS = $(addprefix build/obj/, $(notdir $(C_SRCS:.c=.o))) C_OBJS = $(addprefix build/obj/, $(notdir $(C_SRCS:.c=.o)))
ifeq ($(CXX_SRCS_EXTRA),) ifeq ($(CXX_SRCS_EXTRA),)

View File

@ -1,12 +0,0 @@
/*
* Copyright (C) 2023 Orastron Srl unipersonale
*/
#include "memset.h"
void *memset(void *ptr, int value, size_t num) {
unsigned char *p = (unsigned char *)ptr;
for (size_t i = 0; i < num; i++)
p[i] = (unsigned char)value;
return ptr;
}

View File

@ -8,7 +8,7 @@
#include "data.h" #include "data.h"
#include "plugin.h" #include "plugin.h"
#include "memset.h" #include "string.h"
#include "walloc.h" #include "walloc.h"
typedef struct { typedef struct {

View File

@ -0,0 +1,20 @@
/*
* Copyright (C) 2023, 2024 Orastron Srl unipersonale
*/
#include "string.h"
void *memset(void *ptr, int value, size_t num) {
unsigned char *p = (unsigned char *)ptr;
for (size_t i = 0; i < num; i++)
p[i] = (unsigned char)value;
return ptr;
}
void *memcpy(void *dest, const void *src, size_t num) {
char *d = (char *)dest;
char *s = (char *)src;
for (size_t i = 0; i < num; i++)
d[i] = s[i];
return dest;
}

View File

@ -2,8 +2,8 @@
* Copyright (C) 2023 Orastron Srl unipersonale * Copyright (C) 2023 Orastron Srl unipersonale
*/ */
#ifndef MEMSET_H #ifndef STRING_H
#define MEMSET_H #define STRING_H
#include <stddef.h> #include <stddef.h>
@ -12,6 +12,7 @@ extern "C" {
#endif #endif
void *memset(void *ptr, int value, size_t num); void *memset(void *ptr, int value, size_t num);
void *memcpy(void *dest, const void *src, size_t num);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -5,7 +5,7 @@
#include "walloc.h" #include "walloc.h"
#include <stdint.h> #include <stdint.h>
#include "memset.h" #include "string.h"
extern unsigned char __heap_base; extern unsigned char __heap_base;

View File

@ -2,8 +2,8 @@ var path = require("path");
var sep = path.sep; var sep = path.sep;
module.exports = function (data, api) { module.exports = function (data, api) {
api.copyFile(`src${sep}memset.h`, `src${sep}memset.h`); api.copyFile(`src${sep}string.h`, `src${sep}string.h`);
api.copyFile(`src${sep}memset.c`, `src${sep}memset.c`); api.copyFile(`src${sep}string.c`, `src${sep}string.c`);
api.copyFile(`src${sep}walloc.h`, `src${sep}walloc.h`); api.copyFile(`src${sep}walloc.h`, `src${sep}walloc.h`);
api.copyFile(`src${sep}walloc.c`, `src${sep}walloc.c`); api.copyFile(`src${sep}walloc.c`, `src${sep}walloc.c`);
api.copyFile(`src${sep}new.cpp`, `src${sep}new.cpp`); api.copyFile(`src${sep}new.cpp`, `src${sep}new.cpp`);