APPEND Command Is Not Utilized with access() Function

Last reviewed: July 17, 1997
Article ID: Q49006
6.00 6.00a 6.00ax 7.00 | 1.00 1.50 1.51 1.52
MS-DOS                 | WINDOWS
kbprg

The information in this article applies to:

  • The C Run-time (CRT), included with:

        - Microsoft C for MS-DOS, versions 5.1, 6.0, 6.0a, and 6.0ax
        - Microsoft C/C++ for MS-DOS, version 7.0
        - Microsoft Visual C++ for Windows, versions 1.0, 1.5, 1.51, and 1.52
    

SUMMARY

The Microsoft C Run-time library function, access(), determines whether or not a specified file exists and can be accessed in read and/or write mode(s). The access() function searches the current working directory for the particular file or the directory specified by a path to the file.

The MS-DOS and Windows NT APPEND command, which establishes a search path for data files and works similarly to the PATH environment variable, appears to be a way to assist access() in finding files outside the current working directory without having to supply a path. However, the APPEND command does not search the data path when locating a file to be used by the access() function. Consequently, access() fails when searching for a file issued with no path and that is not in the current working directory.

MORE INFORMATION

Under MS-DOS, APPEND searches the data path for files only when the following MS-DOS system calls are made:

   Code          Function
   ----          --------

   0FH           Open File (FCB)
   23H           Get (FCB) File Size
   3DH           Open Handle
   11H           FCB search first  (with /x switch only)
   4EH           Handle find first (with /x switch only)
   4BH           Exec (with /x switch only)

In the MS-DOS version of the C run-time library, the access() function makes an MS-DOS system call to interrupt 21H function 43H, which sets and retrieves file attributes. Since this is not a system call listed above, APPEND does not perform file searching.

In the 32-bit version of the C run-time library, the access() function makes a call to the Win32 function GetFileAttributes(). The Windows NT version of APPEND does not trap this call and as a result does not search the data path for the file.

The following program illustrates the APPEND limitation. The program uses access() to determine whether the file named TEST exists. Assume that the TEST data file is not in the current working directory, but instead is in a directory called c:\mydata, and that the APPEND command "APPEND=c:\mydata" was issued previously to set the appropriate search path.

Sample Code

/* Compile options needed: none
*/

#include <io.h>
#include <fcntl.h>
#include <stdio.h>

FILE * stream;

void main( void )
{
    /* check for existence of TEST fails despite having APPEND set */
    if ((access( "TEST", 0 )) == -1 )
        printf( "File 'TEST' was not found with access()\n\n" );
    else
        printf( "File 'TEST' was found with access()\n\n" );

    /* however, fopen() recognizes APPEND for successful access */
    if ((stream = fopen( "TEST", "r")) != NULL )
        printf( "File 'TEST' opened successfully fopen()\n" );
    else
        printf( "File 'TEST' was not opened successfully with fopen()\n" );
}

REFERENCES

  • Page 363 of the MS-DOS version 5.0 User's Guide and Reference.
  • The MS-DOS Help menu.
  • The Windows NT Help menu.


Additional reference words: kbinf 1.00 1.50 5.10 6.00 6.00a 6.00ax 7.00
KBCategory: kbprg
KBSubcategory: CRTIss
Keywords : kb16bitonly


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 17, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.