Microsoft KB Archive/49006

From BetaArchive Wiki

APPEND Command Is Not Utilized with access() Function


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 #include #include 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
Issue type :
Technology : kbVCsearch kbAudDeveloper kbCRT

Last Reviewed: May 5, 2001
© 2001 Microsoft Corporation. All rights reserved. Terms of Use.