APPEND Command Is Not Utilized with access() FunctionLast reviewed: July 17, 1997Article ID: Q49006 |
6.00 6.00a 6.00ax 7.00 | 1.00 1.50 1.51 1.52
MS-DOS | WINDOWSkbprg The information in this article applies to:
SUMMARYThe 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 INFORMATIONUnder 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
|
Additional reference words: kbinf 1.00 1.50 5.10 6.00 6.00a 6.00ax 7.00
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |