summaryrefslogtreecommitdiff
path: root/klibc/klibc
diff options
context:
space:
mode:
Diffstat (limited to 'klibc/klibc')
-rw-r--r--klibc/klibc/MCONFIG2
-rw-r--r--klibc/klibc/Makefile12
-rw-r--r--klibc/klibc/README5
-rw-r--r--klibc/klibc/SYSCALLS.def15
-rw-r--r--klibc/klibc/arch/ia64/pipe.c2
-rw-r--r--klibc/klibc/arch/m32r/MCONFIG18
-rw-r--r--klibc/klibc/arch/m32r/Makefile.inc19
-rw-r--r--klibc/klibc/arch/m32r/crt0.S25
-rw-r--r--klibc/klibc/arch/m32r/setjmp.S47
-rw-r--r--klibc/klibc/arch/m32r/syscall.S29
-rw-r--r--klibc/klibc/arch/m32r/sysstub.ph25
-rw-r--r--klibc/klibc/arch/ppc/setjmp.S2
-rw-r--r--klibc/klibc/arch/ppc64/MCONFIG6
-rw-r--r--klibc/klibc/arch/ppc64/Makefile.inc2
-rw-r--r--klibc/klibc/arch/ppc64/sysstub.ph5
-rw-r--r--klibc/klibc/arch/x86_64/MCONFIG6
-rw-r--r--klibc/klibc/asprintf.c4
-rw-r--r--klibc/klibc/atexit.h2
-rw-r--r--klibc/klibc/exitc.c15
-rw-r--r--klibc/klibc/fork.c3
-rw-r--r--klibc/klibc/jrand48.c12
-rw-r--r--klibc/klibc/makeerrlist.pl21
-rw-r--r--klibc/klibc/sbrk.c2
-rw-r--r--klibc/klibc/strcspn.c11
-rw-r--r--klibc/klibc/strpbrk.c14
-rw-r--r--klibc/klibc/strspn.c62
-rw-r--r--klibc/klibc/strxspn.c30
-rw-r--r--klibc/klibc/strxspn.h13
-rw-r--r--klibc/klibc/syslog.c13
-rw-r--r--klibc/klibc/vasprintf.c4
30 files changed, 306 insertions, 120 deletions
diff --git a/klibc/klibc/MCONFIG b/klibc/klibc/MCONFIG
index 5b6eecd037..499b6e8b56 100644
--- a/klibc/klibc/MCONFIG
+++ b/klibc/klibc/MCONFIG
@@ -13,6 +13,6 @@ ifeq ($(ERRLIST),1)
REQFLAGS += -DWITH_ERRLIST
endif
-CFLAGS = -Wp,-MD,$(dir $*).$(notdir $*).d $(OPTFLAGS) $(REQFLAGS) $(WARNFLAGS)
+CFLAGS = -Wp,-MT,$@,-MD,$(dir $@).$(notdir $@).d $(OPTFLAGS) $(REQFLAGS) $(WARNFLAGS)
SOFLAGS = -fPIC
diff --git a/klibc/klibc/Makefile b/klibc/klibc/Makefile
index 3519b45089..0d44ce5494 100644
--- a/klibc/klibc/Makefile
+++ b/klibc/klibc/Makefile
@@ -34,8 +34,8 @@ LIBOBJS = vsnprintf.o snprintf.o vsprintf.o sprintf.o \
strcasecmp.o strncasecmp.o strndup.o strerror.o \
strcat.o strchr.o strcmp.o strcpy.o strdup.o strlen.o strnlen.o \
strncat.o strlcpy.o strlcat.o \
- strstr.o strncmp.o strncpy.o strrchr.o strspn.o \
- strsep.o strtok.o \
+ strstr.o strncmp.o strncpy.o strrchr.o \
+ strxspn.o strspn.o strcspn.o strpbrk.o strsep.o strtok.o \
gethostname.o getdomainname.o getcwd.o \
seteuid.o setegid.o \
getenv.o setenv.o putenv.o __put_env.o unsetenv.o \
@@ -59,7 +59,7 @@ LIB = libc.a
INTERP_O = interp.o
-all: $(CRT0) $(LIB) $(SOLIB) klibc.so
+all: tests $(CRT0) $(LIB) $(SOLIB) klibc.so
# Add any architecture-specific rules
include arch/$(ARCH)/Makefile.inc
@@ -120,14 +120,14 @@ crt0.o: arch/$(ARCH)/crt0.o
cp arch/$(ARCH)/crt0.o .
errlist.c:
- $(PERL) makeerrlist.pl -errlist > $@ || rm -f $@
+ $(PERL) makeerrlist.pl -q $(INCLUDE) -errlist > $@ || rm -f $@
# We pass -ansi to keep cpp from define e.g. "i386" as well as "__i386__"
SYSCALLS.i: SYSCALLS.def
$(CC) $(CFLAGS) -D__ASSEMBLY__ -ansi -x assembler-with-cpp -E -o $@ $<
-syscalls.nrs: ../include/sys/syscall.h ../include/arch/$(ARCH)/klibc/archsys.h ../linux/include/asm/unistd.h
- $(CC) $(CFLAGS) -Wp,-dM -x c -E -o $@ ../include/sys/syscall.h
+syscalls.nrs: ../include/sys/syscall.h
+ $(CC) $(CFLAGS) -Wp,-dM -x c -E -o $@ $<
syscalls.dir: SYSCALLS.i syscalls.pl arch/$(ARCH)/sysstub.ph syscommon.h syscalls.nrs
rm -rf syscalls
diff --git a/klibc/klibc/README b/klibc/klibc/README
index edc8524f22..3a53a8809f 100644
--- a/klibc/klibc/README
+++ b/klibc/klibc/README
@@ -38,10 +38,11 @@ b) If you're cross-compiling, change ARCH in the main MCONFIG file to
arm-thumb: Untested
arm26: Not yet ported
arm: Working
- cris: Untested
+ cris: Working
h8300: Not yet ported
i386: Working
ia64: Working
+ m32r: Untested
m68k: Not yet ported
mips64: Not yet ported
mips: Working
@@ -51,7 +52,7 @@ b) If you're cross-compiling, change ARCH in the main MCONFIG file to
s390: Working static, shared untested
s390x: Working
sh: Untested
- sparc64: sigaction() fails in ash for unknown reason
+ sparc64: Untested
sparc: Working
v850: Not yet ported
x86-64: Working
diff --git a/klibc/klibc/SYSCALLS.def b/klibc/klibc/SYSCALLS.def
index dbd7dc8434..4591d0b983 100644
--- a/klibc/klibc/SYSCALLS.def
+++ b/klibc/klibc/SYSCALLS.def
@@ -15,6 +15,7 @@
;
; Process-related syscalls
;
+<!i386,x86_64> void _exit,exit::_exit(int)
<?!ia64> pid_t clone::__clone(unsigned long, void *)
<?ia64> pid_t clone::__clone2(unsigned long, void *, void *)
<?!sparc> pid_t fork()
@@ -65,7 +66,7 @@ int setresuid32,setresuid::setresuid(int, uid_t, uid, uid_t)
int mount(const char *, const char *, const char *, unsigned long, const void *)
<!alpha,ia64> int umount2(const char *, int)
<alpha,ia64> int umount::umount2(const char *, int)
-<!m68k> int pivot_root(const char *, const char *)
+<?> int pivot_root(const char *, const char *)
int sync()
#ifdef __NR_statfs64
int statfs64::__statfs64(const char *, size_t, struct statfs *)
@@ -99,9 +100,12 @@ mode_t umask(mode_t)
int chroot(const char *)
int symlink(const char *, const char *)
int readlink(const char *, char *, size_t)
-int stat64,stat::stat(const char *, struct stat *)
-int lstat64,lstat::lstat(const char *, struct stat *)
-int fstat64,fstat::fstat(int, struct stat *)
+<!ppc64> int stat64,stat::stat(const char *, struct stat *)
+<!ppc64> int lstat64,lstat::lstat(const char *, struct stat *)
+<!ppc64> int fstat64,fstat::fstat(int, struct stat *)
+<ppc64> int stat::stat(const char *, struct stat *)
+<ppc64> int lstat::lstat(const char *, struct stat *)
+<ppc64> int fstat::fstat(int, struct stat *)
int getdents64,getdents::getdents(unsigned int, struct dirent *, unsigned int)
int chown32,chown::chown(const char *, uid_t, gid_t)
int fchown32,fchown::fchown(int, uid_t, gid_t)
@@ -123,7 +127,8 @@ int close(int)
int dup(int)
int dup2(int, int)
<i386> int fcntl64@varadic::fcntl(int, int, unsigned long)
-<!i386> int fcntl64,fcntl::fcntl(int, int, unsigned long)
+<ppc64> int fcntl(int, int, unsigned long)
+<!i386,ppc64> int fcntl64,fcntl::fcntl(int, int, unsigned long)
int ioctl(int, int, void *)
int flock(int, int)
int _newselect,select::select(int, fd_set *, fd_set *, fd_set *, struct timeval *)
diff --git a/klibc/klibc/arch/ia64/pipe.c b/klibc/klibc/arch/ia64/pipe.c
index 0b641e8702..87a6981e55 100644
--- a/klibc/klibc/arch/ia64/pipe.c
+++ b/klibc/klibc/arch/ia64/pipe.c
@@ -2,7 +2,7 @@
* pipe.c
*/
-#include "syscommon.h"
+#include <sys/syscall.h>
#include <klibc/archsys.h>
#define ASM_CLOBBERS ,"out2", "out3", "out4", "out5", "out6", "out7", \
diff --git a/klibc/klibc/arch/m32r/MCONFIG b/klibc/klibc/arch/m32r/MCONFIG
new file mode 100644
index 0000000000..6706d9ddc1
--- /dev/null
+++ b/klibc/klibc/arch/m32r/MCONFIG
@@ -0,0 +1,18 @@
+# -*- makefile -*-
+#
+# arch/m32r/MCONFIG
+#
+# Special rules for this architecture. Note that this is actually
+# included from the main Makefile, and that pathnames should be
+# accordingly.
+#
+
+OPTFLAGS = -Os -fomit-frame-pointer
+BITSIZE = 32
+
+# Extra linkflags when building the shared version of the library
+# This address needs to be reachable using normal inter-module
+# calls, and work on the memory models for this architecture
+# 224 MB - normal binaries start at 0 (?)
+# (lib?)gcc on cris seems to insist on producing .init and .fini sections
+SHAREDFLAGS = --section-start .init=0x0e000100
diff --git a/klibc/klibc/arch/m32r/Makefile.inc b/klibc/klibc/arch/m32r/Makefile.inc
new file mode 100644
index 0000000000..43cb44ef8f
--- /dev/null
+++ b/klibc/klibc/arch/m32r/Makefile.inc
@@ -0,0 +1,19 @@
+# -*- makefile -*-
+#
+# arch/m32r/Makefile.inc
+#
+# Special rules for this architecture. Note that this is actually
+# included from the main Makefile, and that pathnames should be
+# accordingly.
+#
+
+ARCHOBJS = \
+ arch/$(ARCH)/setjmp.o \
+ arch/$(ARCH)/syscall.o \
+ libgcc/__divdi3.o \
+ libgcc/__moddi3.o \
+ libgcc/__udivdi3.o \
+ libgcc/__umoddi3.o \
+ libgcc/__udivmoddi4.o
+
+archclean:
diff --git a/klibc/klibc/arch/m32r/crt0.S b/klibc/klibc/arch/m32r/crt0.S
new file mode 100644
index 0000000000..1589a774a2
--- /dev/null
+++ b/klibc/klibc/arch/m32r/crt0.S
@@ -0,0 +1,25 @@
+#
+# arch/m32r/crt0.S
+#
+# Does arch-specific initialization and invokes __libc_init
+# with the appropriate arguments.
+#
+# See __static_init.c or __shared_init.c for the expected
+# arguments.
+#
+
+ .text
+ .balign 4
+ .type _start,@function
+ .globl _start
+_start:
+ /* Save the address of the ELF argument array */
+ mv r0, sp
+
+ /* atexit() function (assume null) */
+ xor r1, r1
+
+ bl __libc_init
+
+ .size _start, .-_start
+
diff --git a/klibc/klibc/arch/m32r/setjmp.S b/klibc/klibc/arch/m32r/setjmp.S
new file mode 100644
index 0000000000..14ef7e3577
--- /dev/null
+++ b/klibc/klibc/arch/m32r/setjmp.S
@@ -0,0 +1,47 @@
+#
+# arch/m32r/setjmp.S
+#
+# setjmp/longjmp for the M32R architecture
+#
+
+#
+# The jmp_buf is assumed to contain the following, in order:
+# r8-r15
+#
+# Note that r14 is the return address register and
+# r15 is the stack pointer.
+#
+
+ .text
+ .balign 4
+ .globl setjmp
+ .type setjmp, @function
+setjmp:
+ st r8, @r0
+ st r9, @+r0
+ st r10, @+r0
+ st r11, @+r0
+ st r12, @+r0
+ st r13, @+r0
+ st r14, @+r0
+ st r15, @+r0
+ xor r0, r0
+ jmp r14
+ .size setjmp,.-setjmp
+
+ .text
+ .balign 4
+ .globl longjmp
+ .type longjmp, @function
+longjmp:
+ ld r8, @r0+
+ ld r9, @r0+
+ ld r10, @r0+
+ ld r11, @r0+
+ ld r12, @r0+
+ ld r13, @r0+
+ ld r14, @r0+
+ ld r15, @r0
+ mv r0, r1
+ jmp r14
+ .size longjmp,.-longjmp
diff --git a/klibc/klibc/arch/m32r/syscall.S b/klibc/klibc/arch/m32r/syscall.S
new file mode 100644
index 0000000000..a20a33667f
--- /dev/null
+++ b/klibc/klibc/arch/m32r/syscall.S
@@ -0,0 +1,29 @@
+/*
+ * arch/m32r/syscall.S
+ *
+ * r7 contains the syscall number (set by stub);
+ * r0..r3 contains arguments 0-3 per standard calling convention;
+ * r4..r5 contains arguments 4-5, but we have to get those from
+ * the stack.
+ */
+
+ .section ".text","ax"
+ .balign 4
+ .globl __syscall_common
+ .type __syscall_common,@function
+__syscall_common:
+ ld r4,@sp
+ ld r5,@(4,sp)
+ trap #2
+ cmpi r0, #-4096
+ bnc 1f
+ jmp r14
+1:
+ seth r2,#high(errno)
+ or3 r2,r2,#low(errno)
+ neg r1,r0
+ st r1,@r7
+ ldi r0,#-1
+ jmp r14
+
+ .size __syscall_common,.-__syscall_common
diff --git a/klibc/klibc/arch/m32r/sysstub.ph b/klibc/klibc/arch/m32r/sysstub.ph
new file mode 100644
index 0000000000..3813ea4144
--- /dev/null
+++ b/klibc/klibc/arch/m32r/sysstub.ph
@@ -0,0 +1,25 @@
+# -*- perl -*-
+#
+# arch/m32r/sysstub.ph
+#
+# Script to generate system call stubs
+#
+
+sub make_sysstub($$$$@) {
+ my($fname, $type, $sname, $stype, @args) = @_;
+
+ open(OUT, '>', "syscalls/${fname}.S");
+ print OUT "#include <asm/unistd.h>\n";
+ print OUT "\n";
+ print OUT "\t.text\n";
+ print OUT "\t.type\t${fname},\@function\n";
+ print OUT "\t.globl\t${fname}\n";
+ print OUT "\t.balign\t4\n";
+ print OUT "${fname}:\n";
+ print OUT "\tldi\tr7,#__NR_${sname}\n";
+ print OUT "\tbra\t__syscall_common\n";
+ print OUT "\t.size ${fname},.-${fname}\n";
+ close(OUT);
+}
+
+1;
diff --git a/klibc/klibc/arch/ppc/setjmp.S b/klibc/klibc/arch/ppc/setjmp.S
index 1c50301707..3012de3ea6 100644
--- a/klibc/klibc/arch/ppc/setjmp.S
+++ b/klibc/klibc/arch/ppc/setjmp.S
@@ -32,4 +32,4 @@ longjmp:
blr /* return */
.size longjmp,.-longjmp
- \ No newline at end of file
+
diff --git a/klibc/klibc/arch/ppc64/MCONFIG b/klibc/klibc/arch/ppc64/MCONFIG
index 86526f895c..09881b8d40 100644
--- a/klibc/klibc/arch/ppc64/MCONFIG
+++ b/klibc/klibc/arch/ppc64/MCONFIG
@@ -7,8 +7,10 @@
# accordingly.
#
-OPTFLAGS = -Os -fomit-frame-pointer
-BITSIZE = 64
+ARCHREQFLAGS = -m64 -mcall-aixdesc
+OPTFLAGS = -Os -fomit-frame-pointer
+BITSIZE = 64
+LDFLAGS = -m elf64ppc
# Extra linkflags when building the shared version of the library
# This address needs to be reachable using normal inter-module
diff --git a/klibc/klibc/arch/ppc64/Makefile.inc b/klibc/klibc/arch/ppc64/Makefile.inc
index 928df1aeb7..d1e128fdce 100644
--- a/klibc/klibc/arch/ppc64/Makefile.inc
+++ b/klibc/klibc/arch/ppc64/Makefile.inc
@@ -19,7 +19,7 @@ interp.o: interp1.o klibc.got
$(LD) $(LDFLAGS) -r -o $@ interp1.o klibc.got
klibc.got: $(SOHASH)
- $(OBJCOPY) -j.got $< $@
+ $(OBJCOPY) -j .got $< $@
archclean:
rm -f klibc.got
diff --git a/klibc/klibc/arch/ppc64/sysstub.ph b/klibc/klibc/arch/ppc64/sysstub.ph
index 1469cc6071..0a379158e1 100644
--- a/klibc/klibc/arch/ppc64/sysstub.ph
+++ b/klibc/klibc/arch/ppc64/sysstub.ph
@@ -16,16 +16,13 @@ sub make_sysstub($$$$@) {
print OUT "\t.align 3\n";
print OUT "${fname}:\n";
print OUT "\t.quad .${fname},.TOC.\@tocbase,0\n";
- print OUT "\t.size ${fname},24\n";
print OUT "\t.text\n";
print OUT "\t.type .${fname},\@function\n";
print OUT "\t.globl .${fname}\n";
print OUT ".${fname}:\n";
print OUT "\tli 0,__NR_${sname}\n";
print OUT "\tsc\n";
- print OUT "\tmfcr 0\n";
- print OUT "\trldicl. 9,0,36,63\n";
- print OUT "\tbeqlr- 0\n";
+ print OUT "\tbnslr\n";
print OUT "\tb .__syscall_error\n";
print OUT "\t.size .${fname},.-.${fname}\n";
close(OUT);
diff --git a/klibc/klibc/arch/x86_64/MCONFIG b/klibc/klibc/arch/x86_64/MCONFIG
index f3c87410a6..a2a2367633 100644
--- a/klibc/klibc/arch/x86_64/MCONFIG
+++ b/klibc/klibc/arch/x86_64/MCONFIG
@@ -20,3 +20,9 @@ OPTFLAGS = -Os -fno-asynchronous-unwind-tables -fomit-frame-pointer \
BITSIZE = 64
LDFLAGS = -m elf_x86_64
+# Extra linkflags when building the shared version of the library
+# This address needs to be reachable using normal inter-module
+# calls, and work on the memory models for this architecture
+# 2 MB - normal binaries start at 4 MB
+SHAREDFLAGS = -Ttext 0x00200200
+
diff --git a/klibc/klibc/asprintf.c b/klibc/klibc/asprintf.c
index 457d34bb15..6002b576e1 100644
--- a/klibc/klibc/asprintf.c
+++ b/klibc/klibc/asprintf.c
@@ -16,10 +16,10 @@ int asprintf(char **bufp, const char *format, ...)
va_start(ap, format);
va_copy(ap1, ap);
- bytes = vsnprintf(NULL, 0, format, ap1);
+ bytes = vsnprintf(NULL, 0, format, ap1) + 1;
va_end(ap1);
- *bufp = p = malloc(bytes+1);
+ *bufp = p = malloc(bytes);
if ( !p )
return -1;
diff --git a/klibc/klibc/atexit.h b/klibc/klibc/atexit.h
index a60d641e23..792141def5 100644
--- a/klibc/klibc/atexit.h
+++ b/klibc/klibc/atexit.h
@@ -13,7 +13,5 @@ struct atexit {
struct atexit *next;
};
-extern struct atexit *__atexit_list;
-
#endif /* ATEXIT_H */
diff --git a/klibc/klibc/exitc.c b/klibc/klibc/exitc.c
index 6e5d78979d..8819737fb7 100644
--- a/klibc/klibc/exitc.c
+++ b/klibc/klibc/exitc.c
@@ -1,9 +1,7 @@
/*
* exit.c
*
- * Note: all programs need exit(), since it's invoked from
- * crt0.o. Therefore there is no point in breaking apart
- * exit() and _exit().
+ * Implement exit()
*/
#include <stdlib.h>
@@ -14,11 +12,6 @@
#if !defined(__i386__) && !defined(__x86_64__)
-#define __NR___exit __NR_exit
-
-/* Syscalls can't return void... */
-static inline _syscall1(int,__exit,int,rv);
-
/* This allows atexit/on_exit to install a hook */
__noreturn (*__exit_handler)(int) = _exit;
@@ -27,10 +20,4 @@ __noreturn exit(int rv)
__exit_handler(rv);
}
-__noreturn _exit(int rv)
-{
- __exit(rv);
- for(;;);
-}
-
#endif
diff --git a/klibc/klibc/fork.c b/klibc/klibc/fork.c
index daf313eaf2..fcd73bd60b 100644
--- a/klibc/klibc/fork.c
+++ b/klibc/klibc/fork.c
@@ -8,11 +8,10 @@
#include <sys/syscall.h>
#include <signal.h>
#include <unistd.h>
+#include <sched.h>
#ifndef __NR_fork
-extern pid_t __clone(unsigned long flags, void * newsp);
-
pid_t fork(void)
{
return __clone(SIGCHLD, 0);
diff --git a/klibc/klibc/jrand48.c b/klibc/klibc/jrand48.c
index a2ead11e5f..660a6e5a71 100644
--- a/klibc/klibc/jrand48.c
+++ b/klibc/klibc/jrand48.c
@@ -10,15 +10,15 @@ long jrand48(unsigned short xsubi[3])
uint64_t x;
/* The xsubi[] array is littleendian by spec */
- x = (uint64_t)xsubi[0] +
- ((uint64_t)xsubi[1] << 16) +
- ((uint64_t)xsubi[2] << 32);
+ x = (uint64_t)(uint16_t)xsubi[0] +
+ ((uint64_t)(uint16_t)xsubi[1] << 16) +
+ ((uint64_t)(uint16_t)xsubi[2] << 32);
x = (0x5deece66dULL * x) + 0xb;
- xsubi[0] = (unsigned short)x;
- xsubi[1] = (unsigned short)(x >> 16);
- xsubi[2] = (unsigned short)(x >> 32);
+ xsubi[0] = (unsigned short)(uint16_t)x;
+ xsubi[1] = (unsigned short)(uint16_t)(x >> 16);
+ xsubi[2] = (unsigned short)(uint16_t)(x >> 32);
return (long)(int32_t)(x >> 16);
}
diff --git a/klibc/klibc/makeerrlist.pl b/klibc/klibc/makeerrlist.pl
index f42704f88a..14498d880a 100644
--- a/klibc/klibc/makeerrlist.pl
+++ b/klibc/klibc/makeerrlist.pl
@@ -10,20 +10,27 @@ use FileHandle;
%errors = ();
%errmsg = ();
$maxerr = -1;
-$rootdir = '../linux/include/'; # Must have trailing /
+@includelist = (); # Include directories
sub parse_file($) {
my($file) = @_;
my($fh) = new FileHandle;
my($line, $error, $msg);
my($kernelonly) = 0;
-
- $file = $rootdir.$file;
+ my($root);
print STDERR "opening $file\n" unless ( $quiet );
- if ( !($fh->open("< ".$file)) ) {
- die "$0: cannot open $file\n";
+ $ok = 0;
+ foreach $root ( @includelist ) {
+ if ( $fh->open($root.'//'.$file, '<') ) {
+ $ok = 1;
+ last;
+ }
+ }
+
+ if ( ! $ok ) {
+ die "$0: Cannot find file $file\n";
}
while ( defined($line = <$fh>) ) {
@@ -61,8 +68,10 @@ foreach $arg ( @ARGV ) {
$quiet = 1;
} elsif ( $arg =~ /^-(errlist|errnos|maxerr)$/ ) {
$type = $arg;
+ } elsif ( $arg =~ '^\-I' ) {
+ push(@includelist, "$'");
} else {
- die "$0: Unknown option: $arg\n";
+ die "$0: Unknown option: $arg\n";
}
}
diff --git a/klibc/klibc/sbrk.c b/klibc/klibc/sbrk.c
index f7401dcfe2..cb0efb21b9 100644
--- a/klibc/klibc/sbrk.c
+++ b/klibc/klibc/sbrk.c
@@ -37,5 +37,5 @@ void *sbrk(ptrdiff_t increment)
}
__current_brk = new_brk;
- return end;
+ return start;
}
diff --git a/klibc/klibc/strcspn.c b/klibc/klibc/strcspn.c
new file mode 100644
index 0000000000..87d644551e
--- /dev/null
+++ b/klibc/klibc/strcspn.c
@@ -0,0 +1,11 @@
+/*
+ * strcspn
+ */
+
+#include "strxspn.h"
+
+size_t
+strcspn(const char *s, const char *reject)
+{
+ return __strxspn(s, reject, 1);
+}
diff --git a/klibc/klibc/strpbrk.c b/klibc/klibc/strpbrk.c
new file mode 100644
index 0000000000..86ea236308
--- /dev/null
+++ b/klibc/klibc/strpbrk.c
@@ -0,0 +1,14 @@
+/*
+ * strpbrk
+ */
+
+#include "strxspn.h"
+
+char *
+strpbrk(const char *s, const char *accept)
+{
+ const char *ss = s+__strxspn(s, accept, 1);
+
+ return *ss ? (char *)ss : NULL;
+}
+
diff --git a/klibc/klibc/strspn.c b/klibc/klibc/strspn.c
index 856a964197..10b1dfc5fa 100644
--- a/klibc/klibc/strspn.c
+++ b/klibc/klibc/strspn.c
@@ -1,67 +1,11 @@
/*
- * strspn, strcspn
+ * strspn
*/
-#include <string.h>
-#include <stddef.h>
-#include <inttypes.h>
-#include <limits.h>
-
-#ifndef LONG_BIT
-#define LONG_BIT (CHAR_BIT*sizeof(long))
-#endif
-
-static inline void
-set_bit(unsigned long *bitmap, unsigned int bit)
-{
- bitmap[bit/LONG_BIT] |= 1UL << (bit%LONG_BIT);
-}
-
-static inline int
-test_bit(unsigned long *bitmap, unsigned int bit)
-{
- return (int)(bitmap[bit/LONG_BIT] >> (bit%LONG_BIT)) & 1;
-}
-
-static size_t
-strxspn(const char *s, const char *map, int parity)
-{
- unsigned long matchmap[((1 << CHAR_BIT)+LONG_BIT-1)/LONG_BIT];
- size_t n = 0;
-
- /* Create bitmap */
- memset(matchmap, 0, sizeof matchmap);
- while ( *map )
- set_bit(matchmap, (unsigned char) *map++);
-
- /* Make sure the null character never matches */
- if ( parity )
- set_bit(matchmap, 0);
-
- /* Calculate span length */
- while ( test_bit(matchmap, (unsigned char) *s++)^parity )
- n++;
-
- return n;
-}
+#include "strxspn.h"
size_t
strspn(const char *s, const char *accept)
{
- return strxspn(s, accept, 0);
+ return __strxspn(s, accept, 0);
}
-
-size_t
-strcspn(const char *s, const char *reject)
-{
- return strxspn(s, reject, 1);
-}
-
-char *
-strpbrk(const char *s, const char *accept)
-{
- const char *ss = s+strxspn(s, accept, 1);
-
- return *ss ? (char *)ss : NULL;
-}
-
diff --git a/klibc/klibc/strxspn.c b/klibc/klibc/strxspn.c
new file mode 100644
index 0000000000..618c0bcdb5
--- /dev/null
+++ b/klibc/klibc/strxspn.c
@@ -0,0 +1,30 @@
+/*
+ * strpbrk
+ */
+
+#include <string.h>
+#include <stddef.h>
+#include <inttypes.h>
+#include <limits.h>
+#include "strxspn.h"
+
+size_t
+__strxspn(const char *s, const char *map, int parity)
+{
+ char matchmap[UCHAR_MAX+1];
+ size_t n = 0;
+
+ /* Create bitmap */
+ memset(matchmap, 0, sizeof matchmap);
+ while ( *map )
+ matchmap[(unsigned char) *map++] = 1;
+
+ /* Make sure the null character never matches */
+ matchmap[0] = parity;
+
+ /* Calculate span length */
+ while ( matchmap[(unsigned char) *s++] ^ parity )
+ n++;
+
+ return n;
+}
diff --git a/klibc/klibc/strxspn.h b/klibc/klibc/strxspn.h
new file mode 100644
index 0000000000..5e1a21922f
--- /dev/null
+++ b/klibc/klibc/strxspn.h
@@ -0,0 +1,13 @@
+/*
+ * strxspn.h
+ */
+
+#ifndef STRXSPN_H
+#define STRXSPN_H
+
+#include <stddef.h>
+
+extern size_t
+__strxspn(const char *s, const char *map, int parity);
+
+#endif
diff --git a/klibc/klibc/syslog.c b/klibc/klibc/syslog.c
index e9d84d9ddc..0cd296ab85 100644
--- a/klibc/klibc/syslog.c
+++ b/klibc/klibc/syslog.c
@@ -18,10 +18,11 @@
#define LOGDEV "/dev/kmsg"
/* Max length of ID string */
-#define MAXID 31 /* MAXID+6 must be < BUFLEN */
+#define MAXID 31 /* MAXID+5 must be < BUFLEN */
int __syslog_fd = -1;
static char id[MAXID+1];
+static int syslog_flags = 0;
void openlog(const char *ident, int option, int facility)
{
@@ -36,8 +37,9 @@ void openlog(const char *ident, int option, int facility)
fcntl(fd, F_SETFD, (long)FD_CLOEXEC);
}
+ syslog_flags = option;
+
strncpy(id, ident?ident:"", MAXID);
- id[MAXID] = '\0'; /* Make sure it's null-terminated */
}
void vsyslog(int prio, const char *format, va_list ap)
@@ -54,7 +56,9 @@ void vsyslog(int prio, const char *format, va_list ap)
buf[2] = '>';
len = 3;
- if ( *id )
+ if ( syslog_flags & LOG_PID )
+ len += sprintf(buf+3, "%s[%u]: ", id, getpid());
+ else if ( *id )
len += sprintf(buf+3, "%s: ", id);
len += vsnprintf(buf+len, BUFLEN-len, format, ap);
@@ -68,6 +72,9 @@ void vsyslog(int prio, const char *format, va_list ap)
fd = 2; /* Failed to open log, write to stderr */
write(fd, buf, len);
+
+ if ( syslog_flags & LOG_PERROR )
+ _fwrite(buf+3, len-3, stderr);
}
void syslog(int prio, const char *format, ...)
diff --git a/klibc/klibc/vasprintf.c b/klibc/klibc/vasprintf.c
index 5066dbbfaf..657bfdc3ef 100644
--- a/klibc/klibc/vasprintf.c
+++ b/klibc/klibc/vasprintf.c
@@ -14,10 +14,10 @@ int vasprintf(char **bufp, const char *format, va_list ap)
va_copy(ap1, ap);
- bytes = vsnprintf(NULL, 0, format, ap1);
+ bytes = vsnprintf(NULL, 0, format, ap1) + 1;
va_end(ap1);
- *bufp = p = malloc(bytes+1);
+ *bufp = p = malloc(bytes);
if ( !p )
return -1;