Implemented fclose() and strrchr()
This commit is contained in:
@@ -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)
|
||||
|
||||
15
photon/libc/stdio/fclose.c
Normal file
15
photon/libc/stdio/fclose.c
Normal 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;
|
||||
}
|
||||
15
photon/libc/string/strrchr.c
Normal file
15
photon/libc/string/strrchr.c
Normal 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;
|
||||
}
|
||||
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user