Browse Prior Art Database

Algorithm to Support the Emulation of UNIX Rename() System Call in OS/2

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

Publishing Venue

IBM

Related People

Hidalgo, DS: AUTHOR [+2]

Abstract

Disclosed is an invention which provides an algorithm that can be used to obtain a very close emulation of the rename() function 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 rename() function is one of these.

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

Algorithm to Support the Emulation of UNIX Rename() System Call in
OS/2

      Disclosed is an invention which provides an algorithm that can
be used to obtain a very close emulation of the rename() function 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 rename() function is one 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 file handling system calls.
These system calls have significantly different semantics from those
of OS/2.  In particular, the differences in the semantics of the
rename() function  present a serious problem for porting software
from UNIX to OS/2.

      This invention provides an algorithm that can be used to adapt
the OS/2 C runtime rename() function to provide the support needed to
implement: (1) Support for renaming a file to the name of an existing
file.  (2) Support for proper handling of error return codes
pertaining to the renaming of subdirectories.

      The algorithm is based on the use of the OS/2
DosQueryPathInfo() system call to determine whether the FromPath and
ToPath names correspond to a file or a subdirectory, and to determine
if the ToPath path corresponds to the name of an existing file.  When
the latter is the case, the algorithm creates a temporary file to
save the file indicated by ToPath and then removes the ToPath file
before calling the C runtime rename() function to rename FromPath to
ToPath.  The C runtime rename() fails when the ToPath file already
exists.  When the call to the C runtime rename() function call fails
for any other reason, the emulation algorithm below restores the
ToPath file from the temporary copy.  This preserves the atomicity
semantics of the UNIX rename() function.

      The detailed description of the algorithm for the OS/2
adaptation of the UNIX rename() system call is given below.  A macro
is provided in the stdlib.h header file to map rename() function
calls to cpp_rename() function calls.
  int cpp_rename(const char * FromPath, const char * ToPath) BEGIN
    Call the OS/2 DosQueryPathInfo() system call to determine if the
      FromPath file is an existing file or a subdirectory name.
    IF the above call fails THEN
    BEGIN
      IF FromPath doesn't exist or any other error THEN
        Set the errno variable to ENOENT.
    ELSE
      Set the errno variable to EACCES.
    Return -1.
  END
   Call the OS/2 DosQueryPa...