summaryrefslogtreecommitdiffstats
path: root/mdk-stage1/dietlibc/libcompat
diff options
context:
space:
mode:
Diffstat (limited to 'mdk-stage1/dietlibc/libcompat')
-rw-r--r--mdk-stage1/dietlibc/libcompat/daemon.c29
-rw-r--r--mdk-stage1/dietlibc/libcompat/getdelim.c32
-rw-r--r--mdk-stage1/dietlibc/libcompat/getline.c9
-rw-r--r--mdk-stage1/dietlibc/libcompat/re_bsd.c34
-rw-r--r--mdk-stage1/dietlibc/libcompat/stpcpy.c6
-rw-r--r--mdk-stage1/dietlibc/libcompat/syscall.S70
6 files changed, 180 insertions, 0 deletions
diff --git a/mdk-stage1/dietlibc/libcompat/daemon.c b/mdk-stage1/dietlibc/libcompat/daemon.c
new file mode 100644
index 000000000..30f97a09a
--- /dev/null
+++ b/mdk-stage1/dietlibc/libcompat/daemon.c
@@ -0,0 +1,29 @@
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <paths.h>
+
+#include "daemon.h"
+
+int daemon (int nochdir,int noclose)
+{
+ int fd;
+ switch (fork()) {
+ case -1: return (-1);
+ case 0: break;
+ default: _exit (0);
+ }
+ if (setsid () == -1) return (-1);
+ if (!nochdir) chdir ("/");
+ if (!noclose) {
+ fd = open(_PATH_DEVNULL,O_RDWR,0);
+ if (fd == -1) return (-1);
+ dup2 (fd,STDIN_FILENO);
+ dup2 (fd,STDOUT_FILENO);
+ dup2 (fd,STDERR_FILENO);
+ if (fd>2) close (fd);
+ }
+ return (0);
+}
+
diff --git a/mdk-stage1/dietlibc/libcompat/getdelim.c b/mdk-stage1/dietlibc/libcompat/getdelim.c
new file mode 100644
index 000000000..e499bd7b7
--- /dev/null
+++ b/mdk-stage1/dietlibc/libcompat/getdelim.c
@@ -0,0 +1,32 @@
+#define _GNU_SOURCE
+#include <stdlib.h>
+#include <stdio.h>
+#include "dietfeatures.h"
+#include <errno.h>
+#include "dietwarning.h"
+
+ssize_t getdelim(char **lineptr, size_t *n, int delim, FILE *stream) {
+ size_t i;
+ if (!lineptr || !n) {
+ errno=EINVAL;
+ return -1;
+ }
+ if (!*lineptr) *n=0;
+ for (i=0; ; ) {
+ int x=fgetc(stream);
+ if (i>=*n) {
+ int tmp=*n+100;
+ char* new=realloc(*lineptr,tmp);
+ if (!new) return -1;
+ *lineptr=new; *n=tmp;
+ }
+ if (x==EOF) { (*lineptr)[i]=0; return -1; }
+ (*lineptr)[i]=x;
+ ++i;
+ if (x==delim) break;
+ }
+ (*lineptr)[i]=0;
+ return i;
+}
+
+link_warning("getdelim","warning: portable software should not use getdelim!")
diff --git a/mdk-stage1/dietlibc/libcompat/getline.c b/mdk-stage1/dietlibc/libcompat/getline.c
new file mode 100644
index 000000000..4926850a7
--- /dev/null
+++ b/mdk-stage1/dietlibc/libcompat/getline.c
@@ -0,0 +1,9 @@
+#define _GNU_SOURCE
+#include <stdio.h>
+#include "dietwarning.h"
+
+#undef getline
+ssize_t getline(char **lineptr, size_t *n, FILE *stream) {
+ return getdelim(lineptr,n,'\n',stream);
+}
+link_warning("getline","warning: you used getline without include stdio.h w/_GNU_SOURCE")
diff --git a/mdk-stage1/dietlibc/libcompat/re_bsd.c b/mdk-stage1/dietlibc/libcompat/re_bsd.c
new file mode 100644
index 000000000..44f022fa3
--- /dev/null
+++ b/mdk-stage1/dietlibc/libcompat/re_bsd.c
@@ -0,0 +1,34 @@
+/* wrapper to simulate the braindead 4.3BSD regex interface
+ * by Andreas Krennmair <a.krennmair@aon.at>
+ */
+#include <regex.h>
+#include <sys/types.h>
+
+#include "dietwarning.h"
+
+static char err_compile[] = "unable to compile regular expression.";
+static int re_buf_used;
+static regex_t re_buf;
+
+char * re_comp(char * regex) {
+ int rc;
+ if (regex) {
+ if (re_buf_used)
+ regfree(&re_buf);
+ rc = regcomp(&re_buf,regex,0);
+ if (rc)
+ return err_compile;
+ re_buf_used = 1;
+ }
+ return NULL;
+}
+
+int re_exec(char * string) {
+ if (string) {
+ return regexec(&re_buf,string,0,NULL,0)?0:1;
+ }
+ return 0;
+}
+
+link_warning("re_comp","warning: use regcomp instead of re_comp!")
+link_warning("re_exec","warning: use regexec instead of re_exec!")
diff --git a/mdk-stage1/dietlibc/libcompat/stpcpy.c b/mdk-stage1/dietlibc/libcompat/stpcpy.c
new file mode 100644
index 000000000..237a2e374
--- /dev/null
+++ b/mdk-stage1/dietlibc/libcompat/stpcpy.c
@@ -0,0 +1,6 @@
+#include <string.h>
+
+char * stpcpy (char *dst, const char *src) {
+ while ((*dst++ = *src++));
+ return (dst-1);
+}
diff --git a/mdk-stage1/dietlibc/libcompat/syscall.S b/mdk-stage1/dietlibc/libcompat/syscall.S
new file mode 100644
index 000000000..dd8e6b827
--- /dev/null
+++ b/mdk-stage1/dietlibc/libcompat/syscall.S
@@ -0,0 +1,70 @@
+#include "dietfeatures.h"
+
+.text
+.globl syscall
+#ifdef __arm__
+.type syscall,function
+#else
+.type syscall,@function
+#endif
+
+syscall:
+#ifdef __i386__
+ movl %esp, %eax
+ pushl %edi
+ pushl %esi
+ pushl %ebx
+ pushl %ebp
+ movl 0x08(%eax), %ebx
+ movl 0x0c(%eax), %ecx
+ movl 0x10(%eax), %edx
+ movl 0x14(%eax), %esi
+ movl 0x18(%eax), %edi
+ movl 0x1c(%eax), %ebp
+ movl 0x04(%eax), %eax
+ int $0x80
+ cmpl $-255, %eax
+ jbe .Lret
+ negl %eax
+#ifdef WANT_THREADSAFE
+ movl %eax, %ebx
+ call __errno_location
+ movl %ebx, (%eax)
+ xorl %eax, %eax
+ decl %eax
+#else
+ mov %eax, errno
+ sbb %eax, %eax
+#endif
+.Lret:
+ pop %ebp
+ pop %ebx
+ pop %esi
+ pop %edi
+ ret
+#elif (defined(__hppa__))
+ copy %r26, %r20
+ copy %r25, %r26
+ copy %r24, %r25
+ copy %r23, %r24
+ ldw -0x34(%sr0, %sp), %r23
+ ldw -0x38(%sr0, %sp), %r22
+ be,l 0x100(%sr2, %r0), %sr0, %r31
+ ldw -0x3c(%sr0, %sp), %r21
+ ldi -0x100, %r1
+ cmpb,<<=,n %r1, %ret0, __error_unified_syscall
+.Lret:
+ bv,n %r0(%rp)
+#elif (defined(__ia64__))
+ mov r15=r32
+ mov r32=r33
+ mov r33=r34
+ mov r34=r35
+ mov r35=r36
+ mov r36=r37
+ break.i 0x100000
+ cmp.eq p6,p0=-1,r10
+(p6) br __error_unified_syscall
+ br.ret.sptk.few rp
+#endif
+.size syscall, . - syscall