DEPFILES := $(OBJ:%.o=%.d)\r
BIN = libc.so\r
ifeq ($(ARCHDIR),native)\r
- #OBJ := $(filter-out heap.o,$(OBJ))\r
+ OBJ := $(filter-out heap.o,$(OBJ))\r
#LDFLAGS += -l c\r
BIN = libc_acess.so\r
endif\r
#include "lib.h"
#include <errno.h>
#include <acess/sys.h>
+#include <string.h>
EXPORT int *libc_geterrno()
{
return &_errno;
}
-EXPORT const char *strerror(int errnum)
+EXPORT char *strerror(int errnum)
{
switch(errnum)
{
case EPERM: return "Permissions error";
default:
_SysDebug("strerror: errnum=%i unk", errnum);
+ errno = EINVAL;
return "unknown error";
}
}
+EXPORT int strerror_r(int errnum, char *buf, size_t bufsiz)
+{
+ const char *str = strerror(errnum);
+ if(!str)
+ return -1;
+
+ strncpy(buf, str, bufsiz);
+ return 0;
+}
+
#ifndef _LIBC_ERRNO_H_
#define _LIBC_ERRNO_H_
-// TODO: Fully implement errno.h, make sure it matches the kernel one
+#include <stddef.h> // size_t
extern int *libc_geterrno(void);
#define errno (*libc_geterrno())
-extern const char *strerror(int errnum);
+extern int strerror_r(int errnum, char *buf, size_t buflen);
+extern char *strerror(int errnum);
#include "errno.enum.h"
# define bsearch acess_bsearch\r
# define qsort acess_qsort\r
\r
+# define free acess_free\r
+# define malloc acess_malloc\r
+# define calloc acess_calloc\r
+# define realloc acess_realloc\r
+# define IsHeap acess_IsHeap\r
+\r
# define srand acess_srand\r
# define rand acess_rand\r
# define rand_p acess_rand_p\r
*/
EXPORT int _vcprintf_int(printf_puts_t puts_cb, void *puts_h, const char *format, va_list args)
{
- char tmp[65];
int c, minSize, precision, len;
size_t pos = 0;
char *p;
pos ++; \
} while(0)
- tmp[32] = '\0';
-
while((c = *format++) != 0)
{
// Non-control character
}
}
- // Just help things along later
- p = tmp;
-
// Get Type
switch( c )
{
valtype = _VCSCANF_NOTYPE;
break;
// match a set of characters
- case '[':
- fch = *format++;
- if( fch == '^' ) {
+ case '[': {
+ int invert = 0;
+ if( *format++ == '^' ) {
// Invert
- fch = *format;
+ invert = 1;
}
set_start = format;
set_len = 0;
if( maxlen == 0 )
maxlen = -1;
ich = 0;
- while( maxlen -- && (ich = __getc(h)) && memchr(set_start, set_len, ich) )
+ while( maxlen -- && (ich = __getc(h)) && invert == !memchr(set_start, set_len, ich) )
{
if(ptr._char) *ptr._char++ = ich;
nch ++;
if(ptr._char) *ptr._char++ = 0;
valtype = _VCSCANF_NOTYPE;
break;
+ }
case 'p': // read back printf("%p")
valtype = _VCSCANF_NOTYPE;
break;
* \fn EXPORT char *strstr(char *str1, const char *str2)
* \brief Search a \a str1 for the first occurance of \a str2
*/
-EXPORT char *strstr(char *str1, const char *str2)
+EXPORT char *strstr(const char *str1, const char *str2)
{
const char *test = str2;
for(;*str1;str1++)
{
- if(*test == '\0') return str1;
+ if(*test == '\0') return (char*)str1;
if(*str1 == *test) test++;
else test = str2;
}