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]

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


Shaun Jackman wrote:
What do you think of this patch? Implementing sleep and usleep with
nanosleep leaves the target only having to implement only the one
function, nanosleep. The definition of mkfifo is pretty universal.

Alternatively, I could now put these functions in
libgloss/arm/linux-syscalls1.c. Although, I'd prefer a more general
location.

Cheers,
Shaun


If we protect the sleep functions with a check for HAVE_NANOSLEEP, then this would be fine. The three users of the libc/posix dir right now are Cygwin, Linux, and powerpcle-*-pe. I can vouch for Linux that this wouldn't be a problem, but I couldn't tell you for the other two as the source code is elsewhere. By adding the flag around the two sleep functions, there can't be any problems generated since noone is currently setting the flag on. I assume you will want to define this flag for a special arm configuration. Future configurations that want to use the posix directory code but don't have nanosleep can also use the current code. Do you want me to add the flag checks?


-- Jeff J.

On 3/28/06, Shaun Jackman <sjackman@gmail.com> wrote:

... 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]