Commit 3a9e48cf authored by Asbjørn Pettersen's avatar Asbjørn Pettersen

OS/2 patches. spawnl()

parent 2856d6a8
Wed May 19 19:48:10 1999 ape@lrdpf.spacetec.no (Asbjorn Pettersen)
* plug-ins/bz2/bz2.c: OS/2 patches. spawn(),,
Wed May 19 01:05:08 MEST 1999 Sven Neumann <sven@gimp.org>
* plug-ins/gap/gap_arr_dialog.c
......
......@@ -34,12 +34,17 @@
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/param.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#ifdef __EMX__
#include <fcntl.h>
#include <process.h>
#endif
#include "libgimp/gimp.h"
......@@ -197,6 +202,41 @@ run (char *name,
g_assert (FALSE);
}
#ifdef __EMX__
static int spawn_bz(char *filename, char* tmpname, char *parms, int *pid)
{
FILE *f;
int tfd;
if (!(f = fopen(filename,"wb"))){
g_message("bz: fopen failed: %s\n", g_strerror(errno));
return -1;
}
/* save fileno(stdout) */
tfd = dup(fileno(stdout));
/* make stdout for this process be the output file */
if (dup2(fileno(f),fileno(stdout)) == -1)
{
g_message ("bz: dup2 failed: %s\n", g_strerror(errno));
close(tfd);
return -1;
}
fcntl(tfd, F_SETFD, FD_CLOEXEC);
*pid = spawnlp (P_NOWAIT, "bzip2", "bzip2", parms, tmpname, NULL);
fclose(f);
/* restore fileno(stdout) */
dup2(tfd,fileno(stdout));
close(tfd);
if (*pid == -1)
{
g_message ("bz: spawn failed: %s\n", g_strerror(errno));
return -1;
}
return 0;
}
#endif
static gint
save_image (char *filename,
gint32 image_ID,
......@@ -241,6 +281,7 @@ save_image (char *filename,
/* return -1; */
/* } */
#ifndef __EMX__
/* fork off a bzip2 process */
if ((pid = fork()) < 0)
{
......@@ -265,6 +306,10 @@ save_image (char *filename,
_exit(127);
}
else
#else /* __EMX__ */
if (spawn_bz(filename, tmpname, "-cf", &pid) == -1)
return -1;
#endif
{
waitpid (pid, &status, 0);
......@@ -301,6 +346,7 @@ load_image (char *filename, gint32 run_mode)
tmpname = params[1].data.d_string;
#ifndef __EMX__
/* fork off a g(un)zip and wait for it */
if ((pid = fork()) < 0)
{
......@@ -325,6 +371,10 @@ load_image (char *filename, gint32 run_mode)
_exit(127);
}
else /* parent process */
#else /* __EMX__ */
if (spawn_bz(filename, tmpname, "-cfd", &pid) == -1)
return -1;
#endif
{
waitpid (pid, &status, 0);
......
......@@ -34,12 +34,17 @@
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/param.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#ifdef __EMX__
#include <fcntl.h>
#include <process.h>
#endif
#include "libgimp/gimp.h"
......@@ -197,6 +202,41 @@ run (char *name,
g_assert (FALSE);
}
#ifdef __EMX__
static int spawn_bz(char *filename, char* tmpname, char *parms, int *pid)
{
FILE *f;
int tfd;
if (!(f = fopen(filename,"wb"))){
g_message("bz: fopen failed: %s\n", g_strerror(errno));
return -1;
}
/* save fileno(stdout) */
tfd = dup(fileno(stdout));
/* make stdout for this process be the output file */
if (dup2(fileno(f),fileno(stdout)) == -1)
{
g_message ("bz: dup2 failed: %s\n", g_strerror(errno));
close(tfd);
return -1;
}
fcntl(tfd, F_SETFD, FD_CLOEXEC);
*pid = spawnlp (P_NOWAIT, "bzip2", "bzip2", parms, tmpname, NULL);
fclose(f);
/* restore fileno(stdout) */
dup2(tfd,fileno(stdout));
close(tfd);
if (*pid == -1)
{
g_message ("bz: spawn failed: %s\n", g_strerror(errno));
return -1;
}
return 0;
}
#endif
static gint
save_image (char *filename,
gint32 image_ID,
......@@ -241,6 +281,7 @@ save_image (char *filename,
/* return -1; */
/* } */
#ifndef __EMX__
/* fork off a bzip2 process */
if ((pid = fork()) < 0)
{
......@@ -265,6 +306,10 @@ save_image (char *filename,
_exit(127);
}
else
#else /* __EMX__ */
if (spawn_bz(filename, tmpname, "-cf", &pid) == -1)
return -1;
#endif
{
waitpid (pid, &status, 0);
......@@ -301,6 +346,7 @@ load_image (char *filename, gint32 run_mode)
tmpname = params[1].data.d_string;
#ifndef __EMX__
/* fork off a g(un)zip and wait for it */
if ((pid = fork()) < 0)
{
......@@ -325,6 +371,10 @@ load_image (char *filename, gint32 run_mode)
_exit(127);
}
else /* parent process */
#else /* __EMX__ */
if (spawn_bz(filename, tmpname, "-cfd", &pid) == -1)
return -1;
#endif
{
waitpid (pid, &status, 0);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment