Implemented fclose() and strrchr()

This commit is contained in:
Max Wash
2020-07-18 17:22:20 +01:00
parent 89e40d126b
commit 17ce639206
4 changed files with 41 additions and 0 deletions

View File

@@ -19,6 +19,8 @@ extern int strncmp(const char *a, const char *b, size_t sz);
extern char *strcpy(char *dest, const char *src);
extern char *strncpy(char *dest, const char *src, size_t sz);
extern char *strrchr(const char *s, int c);
extern char *strdup(const char *s);
#if defined(__cplusplus)

View File

@@ -0,0 +1,15 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <__fio.h>
int fclose(FILE *fp)
{
int res = __fio_fclose(fp);
if (res != 0) {
return EOF;
}
free(fp);
return 0;
}

View File

@@ -0,0 +1,15 @@
#include <string.h>
char *strrchr(const char *s, int c)
{
/* include null term */
long sz = strlen(s) + 1;
for (long i = sz; i >= 0; i--) {
if (s[i] == c) {
return (char *)(s + i);
}
}
return NULL;
}

View File

@@ -61,6 +61,15 @@ int __fio_fopen(const char *path, const char *mode, struct __io_file *fp)
return 0;
}
int __fio_fclose(struct __io_file *fp)
{
if (mx_handle_close(fp->handle) != MX_OK) {
return -1;
}
return 0;
}
int __fio_fdopen(mx_handle_t fd, const char *mode, struct __io_file *fp)
{
/* TODO validate handle and mode */