summaryrefslogtreecommitdiffstats
path: root/libc/stdio/popen.c
diff options
context:
space:
mode:
authorCarmelo Amoroso <carmelo.amoroso@st.com>2008-07-09 16:47:01 +0000
committerCarmelo Amoroso <carmelo.amoroso@st.com>2008-07-09 16:47:01 +0000
commit62a21af8006ab04282fdc354c5b4dc765f56d058 (patch)
tree568761d58289238aa14cced3f0010809d4d28c00 /libc/stdio/popen.c
parentef250238dc1572caf859c2b64652f9cdfb0d9e42 (diff)
downloaduClibc-alpine-62a21af8006ab04282fdc354c5b4dc765f56d058.tar.bz2
uClibc-alpine-62a21af8006ab04282fdc354c5b4dc765f56d058.tar.xz
BIG BIG commit: all left files merged from trunk [rev 22714]. Currenntly NPTL sh4 port build and work fine. All committed to allow Khem Ray working on a working branch to integrate the ARM nptl port. MIPS nptl port not tested but should still building and working fine. There are some other part non yet merged with trunk (misc/internals and some headers file that need some more work). Signed-off-by: Carmelo Amoroso <carmelo.amoroso@st.com>
Diffstat (limited to 'libc/stdio/popen.c')
-rw-r--r--libc/stdio/popen.c34
1 files changed, 17 insertions, 17 deletions
diff --git a/libc/stdio/popen.c b/libc/stdio/popen.c
index 044426abf..43d07fa0f 100644
--- a/libc/stdio/popen.c
+++ b/libc/stdio/popen.c
@@ -20,6 +20,11 @@
#include <errno.h>
#include <unistd.h>
#include <sys/wait.h>
+#include <bits/uClibc_mutex.h>
+
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning "hmm... susv3 says Pipe streams are byte-oriented."
+#endif /* __UCLIBC_MJN3_ONLY__ */
libc_hidden_proto(close)
libc_hidden_proto(_exit)
@@ -34,23 +39,16 @@ libc_hidden_proto(fclose)
/* uClinux-2.0 has vfork, but Linux 2.0 doesn't */
#include <sys/syscall.h>
#if ! defined __NR_vfork
-# define vfork fork
+# define vfork fork
# define VFORK_LOCK ((void) 0)
-# define VFORK_UNLOCK ((void) 0)
+# define VFORK_UNLOCK ((void) 0)
libc_hidden_proto(fork)
#endif
-#ifdef __UCLIBC_HAS_THREADS__
-# include <pthread.h>
-# include <pthreadP.h>
-static pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER;
-#endif
-#define LOCK __pthread_mutex_lock(&mylock)
-#define UNLOCK __pthread_mutex_unlock(&mylock)
-
#ifndef VFORK_LOCK
-# define VFORK_LOCK LOCK
-# define VFORK_UNLOCK UNLOCK
+__UCLIBC_MUTEX_STATIC(mylock, PTHREAD_MUTEX_INITIALIZER);
+# define VFORK_LOCK __UCLIBC_MUTEX_LOCK(mylock)
+# define VFORK_UNLOCK __UCLIBC_MUTEX_UNLOCK(mylock)
#endif
struct popen_list_item {
@@ -127,11 +125,11 @@ FILE *popen(const char *command, const char *modes)
if (pid > 0) { /* Parent of vfork... */
pi->pid = pid;
pi->f = fp;
- LOCK;
+ VFORK_LOCK;
pi->next = popen_list;
popen_list = pi;
- UNLOCK;
-
+ VFORK_UNLOCK;
+
return fp;
}
@@ -145,6 +143,8 @@ FILE *popen(const char *command, const char *modes)
return NULL;
}
+#warning is pclose correct wrt the new mutex semantics?
+
int pclose(FILE *stream)
{
struct popen_list_item *p;
@@ -153,7 +153,7 @@ int pclose(FILE *stream)
/* First, find the list entry corresponding to stream and remove it
* from the list. Set p to the list item (NULL if not found). */
- LOCK;
+ VFORK_LOCK;
if ((p = popen_list) != NULL) {
if (p->f == stream) {
popen_list = p->next;
@@ -172,7 +172,7 @@ int pclose(FILE *stream)
} while (1);
}
}
- UNLOCK;
+ VFORK_UNLOCK;
if (p) {
pid = p->pid; /* Save the pid we need */