summaryrefslogtreecommitdiff
path: root/libc/stdio
diff options
context:
space:
mode:
Diffstat (limited to 'libc/stdio')
-rw-r--r--libc/stdio/Makefile2
-rw-r--r--libc/stdio/perror.c19
-rw-r--r--libc/stdio/popen.c49
-rw-r--r--libc/stdio/remove.c23
4 files changed, 92 insertions, 1 deletions
diff --git a/libc/stdio/Makefile b/libc/stdio/Makefile
index fbd0bbf15..874dcae7f 100644
--- a/libc/stdio/Makefile
+++ b/libc/stdio/Makefile
@@ -36,7 +36,7 @@ MOBJ2=printf.o sprintf.o fprintf.o vprintf.o vsprintf.o vfprintf.o snprintf.o vs
MSRC3=scanf.c
MOBJ3=scanf.o sscanf.o fscanf.o vscanf.o vsscanf.o vfscanf.o
-CSRC=dputs.c
+CSRC=dputs.c popen.c perror.c remove.c
COBJS=$(patsubst %.c,%.o, $(CSRC))
OBJS=$(MOBJ) $(MOBJ2) $(MOBJ3) $(COBJS)
diff --git a/libc/stdio/perror.c b/libc/stdio/perror.c
new file mode 100644
index 000000000..d6274c056
--- /dev/null
+++ b/libc/stdio/perror.c
@@ -0,0 +1,19 @@
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+
+void perror(str)
+__const char *str;
+{
+ register char *ptr;
+
+ if (str) {
+ write(2, str, strlen(str));
+ write(2, ": ", 2);
+ } else
+ write(2, "perror: ", 8);
+
+ ptr = strerror(errno);
+ write(2, ptr, strlen(ptr));
+ write(2, "\n", 1);
+}
diff --git a/libc/stdio/popen.c b/libc/stdio/popen.c
new file mode 100644
index 000000000..a07c411eb
--- /dev/null
+++ b/libc/stdio/popen.c
@@ -0,0 +1,49 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+
+FILE *popen(command, rw)
+char *command;
+char *rw;
+{
+ int pipe_fd[2];
+ int pid, reading;
+
+ if (pipe(pipe_fd) < 0)
+ return NULL;
+ reading = (rw[0] == 'r');
+
+ pid = vfork();
+ if (pid < 0) {
+ close(pipe_fd[0]);
+ close(pipe_fd[1]);
+ return NULL;
+ }
+ if (pid == 0) {
+ close(pipe_fd[!reading]);
+ close(reading);
+ if (pipe_fd[reading] != reading) {
+ dup2(pipe_fd[reading], reading);
+ close(pipe_fd[reading]);
+ }
+
+ execl("/bin/sh", "sh", "-c", command, (char *) 0);
+ _exit(255);
+ }
+
+ close(pipe_fd[reading]);
+ return fdopen(pipe_fd[!reading], rw);
+}
+
+int pclose(fd)
+FILE *fd;
+{
+ int waitstat;
+
+ if (fclose(fd) != 0)
+ return EOF;
+ wait(&waitstat);
+ return waitstat;
+}
diff --git a/libc/stdio/remove.c b/libc/stdio/remove.c
new file mode 100644
index 000000000..115b871bb
--- /dev/null
+++ b/libc/stdio/remove.c
@@ -0,0 +1,23 @@
+/* Copyright (C) 1995,1996 Robert de Bath <rdebath@cix.compulink.co.uk>
+ * This file is part of the Linux-8086 C library and is distributed
+ * under the GNU Library General Public License.
+ */
+#include <unistd.h>
+#include <string.h>
+#include <sys/types.h>
+#include <errno.h>
+
+int remove(src)
+__const char *src;
+{
+ extern int errno;
+ int er = errno;
+ int rv = unlink(src);
+
+ if (rv < 0 && errno == EISDIR)
+ rv = rmdir(src);
+ if (rv >= 0)
+ errno = er;
+ return rv;
+}
+