Skip to content

Commit

Permalink
Revise snapshots for tesing purposes
Browse files Browse the repository at this point in the history
  • Loading branch information
jserv committed Dec 7, 2023
1 parent c7c2e9c commit ef73e2b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
41 changes: 23 additions & 18 deletions lib/c.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ int strcmp(char *s1, char *s2)
while (s1[i] && s2[i]) {
if (s1[i] < s2[i])
return -1;
else if (s1[i] > s2[i])
if (s1[i] > s2[i])
return 1;
i++;
}
Expand All @@ -65,7 +65,7 @@ int strncmp(char *s1, char *s2, int len)
while (i < len) {
if (s1[i] < s2[i])
return -1;
else if (s1[i] > s2[i])
if (s1[i] > s2[i])
return 1;
i++;
}
Expand Down Expand Up @@ -100,6 +100,15 @@ char *strncpy(char *dest, char *src, int len)
return dest;
}

char *memcpy(char *dest, char *src, int count)
{
while (count > 0) {
count--;
dest[count] = src[count];
}
return dest;
}

/* set 10 digits (32bit) without div */
void __str_base10(char *pb, int val)
{
Expand Down Expand Up @@ -184,8 +193,10 @@ void __str_base16(char *pb, int val)
pb[c] = '0' + v;
else if (v < 16)
pb[c] = 'a' + v - 10;
else
else {
abort();
break;
}
val = val >> 4;
c--;
}
Expand Down Expand Up @@ -244,6 +255,7 @@ int __format(char *buffer,
break;
default:
abort();
break;
}

while (width > INT_BUF_LEN) {
Expand Down Expand Up @@ -427,15 +439,6 @@ void sprintf(char *buffer, char *str, ...)
buffer[bi] = 0;
}

char *memcpy(char *dest, char *src, int count)
{
while (count > 0) {
count--;
dest[count] = src[count];
}
return dest;
}

int free_all();

void exit(int exit_code)
Expand All @@ -452,19 +455,21 @@ void abort()

FILE *fopen(char *filename, char *mode)
{
if (!strcmp(mode, "wb"))
if (!strcmp(mode, "wb")) {
#if defined(__arm__)
return __syscall(__syscall_open, filename, 65, 0x1fd);
#elif defined(__riscv)
/* FIXME: mode not work currently in RISC-V */
return __syscall(__syscall_openat, -100, filename, 65, 0x1fd);
#endif
if (!strcmp(mode, "rb"))
}
if (!strcmp(mode, "rb")) {
#if defined(__arm__)
return __syscall(__syscall_open, filename, 0, 0);
#elif defined(__riscv)
return __syscall(__syscall_openat, -100, filename, 0, 0);
#endif
}
return NULL;
}

Expand Down Expand Up @@ -565,8 +570,9 @@ void *malloc(int size)
chunk_t *allocated;

if (!freelist_head->next) {
/* If no more chunks in the free chunk list,
allocate best_fit_chunk as NULL. */
/* If no more chunks in the free chunk list, allocate best_fit_chunk
* as NULL.
*/
allocated = best_fit_chunk;
} else {
chunk_t *fh = freelist_head;
Expand All @@ -578,7 +584,7 @@ void *malloc(int size)
/* first time setting fh as best_fit_chunk */
best_fit_chunk = fh;
bsize = fh->size;
} else if (fh->size >= size && best_fit_chunk &&
} else if ((fh->size >= size) && best_fit_chunk &&
(fh->size < bsize)) {
/* If there is a smaller chunk available, replace it. */
best_fit_chunk = fh;
Expand Down Expand Up @@ -666,7 +672,6 @@ void free(void *ptr)
return;

chunk_t *cur = head;

while (cur->ptr != ptr)
cur = cur->next;

Expand Down
2 changes: 1 addition & 1 deletion tests/snapshots/fib.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/snapshots/hello.json

Large diffs are not rendered by default.

0 comments on commit ef73e2b

Please sign in to comment.