Dismiss
InnovationQ will be updated on Sunday, Oct. 22, from 10am ET - noon. You may experience brief service interruptions during that time.
Browse Prior Art Database

Algorithm to Support the Emulation of UNIX Popen() and Pclose() System Calls in OS/2

IP.com Disclosure Number: IPCOM000114636D
Original Publication Date: 1995-Jan-01
Included in the Prior Art Database: 2005-Mar-29
Document File: 4 page(s) / 143K

Publishing Venue

IBM

Related People

Hidalgo, DS: AUTHOR [+2]

Abstract

Disclosed is an invention which provides algorithms that can be used to obtain very close emulations of the popen() and pclose() functions in OS/2*. The emulation of UNIX** system calls is an accepted approach to porting UNIX C source code to OS/2. The differences between these two operating systems makes the emulation of some UNIX system calls particularly challenging. The popen() and pclose() functions are two of these.

This text was extracted from an ASCII text file.
This is the abbreviated version, containing approximately 42% of the total text.

Algorithm to Support the Emulation of UNIX Popen() and Pclose() System
Calls in OS/2

      Disclosed is an invention which provides algorithms that can be
used to obtain very close emulations of the popen() and pclose()
functions in OS/2*.  The emulation of UNIX** system calls is an
accepted approach to porting UNIX C source code to OS/2.  The
differences between these two operating systems makes the emulation
of some UNIX system calls particularly challenging.  The popen() and
pclose() functions are two of these.

      An approach used to port program code written for UNIX
platforms to other operating systems such as OS/2 is to emulate the
UNIX system calls in those operating systems, along with all the
necessary semantics of those calls and the necessary header file
definitions expected by the ported source code.  Some UNIX system
calls are easier to emulate in OS/2 than others.  Of particular
interest are the emulation of the UNIX pipe handling system calls.
UNIX pipe handling system calls have significantly different
interface and semantics from those in OS/2.  There is no direct
correspondence between any type of OS/2 pipe handling interface and
UNIX pipe handling system calls.

      This invention provides algorithms that can be used to obtain
very close OS/2 emulations of the UNIX popen() and pclose() system
calls that are used to standard input/output pipes between a process
and the child process created to execute a command given to popen().
The algorithms are based on the creation of a process to execute the
command passed to popen(), the use of a temporary file to be shared
by that process and the process calling popen(), a data table of
entries containing the name (fname field) and file handle (stream
field) of the temporary files created by popen(), and an OS/2 mutex
semaphore to serialize access to that table.

      The detailed algorithm for an OS/2 emulation of the UNIX
popen() system call is shown below.
  FILE * popen(char *cmd, char *mode) BEGIN
    IF either input parameter is invalid THEN Return NULL.
    If the pipe files table OS/2 mutex latch hasn't been allocated
THEN
    BEGIN
      Allocate the pipe files table OS/2 mutex latch using the
         OS/2 DosCreateMutexSem() system call and store its id in the
         global variable cpp_pfiles_latch so it can also be accessed
by
         the pclose function.
    IF the DosCreateMutexSem() call fails THEN Return NULL.
  END
  Lock the pipe files table latch using the OS/2 DosRequestMutexSem()
  system call.
  IF the DosRequestMutexSem() call fails THEN Return NULL.
  Allocate memory for storing a temporary file name using the
malloc()
  C runtime call.
  IF the caller wants a read-pipe (i.e., mode parameter is "r") THEN
  BEGIN
    Add the redirection string "1>c:\" to a temporary command buffer
    to redirect the command's stdout to a temporary file.
    Set the temporary boolean var...