PRB: _dos_findfirst() with _A_VOLID on MS-DOS vs. Windows NT

ID: Q125496

7.00 | 1.00 1.50 1.51 MS-DOS | WINDOWS kbprg kbprb

The information in this article applies to:

SYMPTOMS

A program calling _dos_findfirst() with the _A_VOLID attribute set behaves differently when run under MS-DOS versus Windows NT. When it's run under MS- DOS, the call can specify any subdirectory and get the volume ID back, if one exists. However when it's run under Windows NT, you will only get the volume ID back if the call specifies the root directory.

CAUSE

This is not a problem with the C Run-time library.

The _dos_findfirst() function puts the user-supplied parameters into the appropriate registers and issues an INT 21h call. The differences observed are due to different operating system implementations of INT 21h Function 4Eh.

RESOLUTION

In order to avoid different behavior when getting the volume ID using _dos_findfirst(), always specify the root directory when making the call.

STATUS

This behavior is by design.

MORE INFORMATION

The following sample code demonstrates this behavior. Make sure you have a volume ID defined for your C drive and that you have a C:\DOS subdirectory containing at least one file. Then run the program first under MS-DOS, then under Windows NT.

The output when run under MS-DOS is:

   _dos_findfirst succeeded in the root directory
   _dos_findfirst succeeded in the DOS directory

The output when run under Windows NT is:

   _dos_findfirst succeeded in the root directory
   _dos_findfirst failed in the DOS directory

Sample Code

/* Compile options needed: none
*/ 

#include <stdio.h>
#include <dos.h>

void main()
{
   struct _find_t info;

   if (!_dos_findfirst("c:\\*.*",_A_VOLID,&info))
      printf("_dos_findfirst succeeded in the root directory\n");
   else printf("_dos_findfirst failed in the root directory\n");

   if (!_dos_findfirst("c:\\dos\\*.*",_A_VOLID,&info))
      printf("_dos_findfirst succeeded in the DOS directory\n");
   else printf("_dos_findfirst failed in the DOS directory\n");
}

Additional reference words: 7.00 1.00 1.50 KBCategory: kbprg kbprb KBSubcategory: CRTIss Keywords : kb16bitonly

Last Reviewed: July 23, 1997