This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] libc/posix: Add mkfifo, sleep, and usleep


... since these functions are all in SUSv3. I poached sleep.c and
usleep.c from libc/sys/linux, with trivial modifications.

Cheers,
Shaun

2006-03-28  Shaun Jackman  <sjackman@gmail.com>

	* libc/posix/Makefile.am (GENERAL_SOURCES): Add mkfifo.c, sleep.c,
	and usleep.c.
	* libc/posix/Makefile.in: Regenerate.
	* libc/posix/mkfifo.c: New file.
	* libc/posix/sleep.c: Ditto.
	* libc/posix/usleep.c: Ditto.

Index: libc/posix/Makefile.am
===================================================================
RCS file: /cvs/src/src/newlib/libc/posix/Makefile.am,v
retrieving revision 1.4
diff -u -r1.4 Makefile.am
--- libc/posix/Makefile.am	26 Aug 2002 18:56:06 -0000	1.4
+++ libc/posix/Makefile.am	28 Mar 2006 23:24:55 -0000
@@ -5,9 +5,9 @@
 INCLUDES = $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS)

 GENERAL_SOURCES = \
-	closedir.c creat.c isatty.c \
+	closedir.c creat.c isatty.c mkfifo.c \
 	opendir.c readdir.c \
-	readdir_r.c rewinddir.c telldir.c
+	readdir_r.c rewinddir.c sleep.c usleep.c telldir.c

 ELIX_2_OBJS = \
         scandir.$(oext) seekdir.$(oext)
--- /dev/null	2006-03-28 07:27:01.510359320 -0700
+++ libc/posix/mkfifo.c	2006-03-28 16:09:00.000000000 -0700
@@ -0,0 +1,14 @@
+/** mkfifo(3)
+ * Written by Shaun Jackman <sjackman@gmail.com>.
+ * Copyright 2006 Pathway Connectivity
+ *
+ * Permission to use, copy, modify, and distribute this software
+ * is freely granted, provided that this notice is preserved.
+ */
+
+#include <sys/stat.h>
+
+int mkfifo(const char *path, mode_t mode)
+{
+	return mknod(path, S_IFIFO | mode, 0);
+}
--- /dev/null	2006-03-28 07:27:01.510359320 -0700
+++ libc/posix/sleep.c	2006-03-28 16:23:33.000000000 -0700
@@ -0,0 +1,18 @@
+/* libc/posix/sleep.c - sleep function */
+
+/* Written 2000 by Werner Almesberger */
+
+#include <errno.h>
+#include <time.h>
+#include <unistd.h>
+
+unsigned sleep(unsigned seconds)
+{
+    struct timespec ts;
+
+    ts.tv_sec = seconds;
+    ts.tv_nsec = 0;
+    if (!nanosleep(&ts,&ts)) return 0;
+    if (errno == EINTR) return ts.tv_sec;
+    return -1;
+}
--- /dev/null	2006-03-28 07:27:01.510359320 -0700
+++ libc/posix/usleep.c	2006-03-28 16:24:21.000000000 -0700
@@ -0,0 +1,18 @@
+/* libc/posix/usleep.c - usleep function */
+
+/* Written 2002 by Jeff Johnston */
+
+#include <errno.h>
+#include <time.h>
+#include <unistd.h>
+
+int usleep(useconds_t useconds)
+{
+    struct timespec ts;
+
+    ts.tv_sec = (long int)useconds / 1000000;
+    ts.tv_nsec = ((long int)useconds % 1000000) * 1000;
+    if (!nanosleep(&ts,&ts)) return 0;
+    if (errno == EINTR) return ts.tv_sec;
+    return -1;
+}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]