PRB: CFile::SetStatus Sets Archive Bit when Not Desired

Last reviewed: July 22, 1997
Article ID: Q117832
7.00 | 1.00 1.50 MS-DOS | WINDOWS kbprg kbprb

The information in this article applies to:

  • The Microsoft Foundation Classes (MFC), included with:

        - Microsoft C/C++ version 7.0
        - Microsoft Visual C++ for Windows, versions 1.0 and 1.5
    

SYMPTOMS

Attempting to clear the archive bit of a file when the archive bit is already cleared causes the archive bit to be set.

CAUSE

This is expected behavior that results when the m_mtime member of the CFileStatus structure is not set to 0, indicating that the time should be updated. Because updating the time has the side effect of setting the archive bit for a file, this action takes precedence over clearing the archive bit when the bit was clear to begin with.

RESOLUTION

  1. If you want to clear only the archive bit, set the m_mtime member to 0, which indicates that you do not want to change the file time:

          CFile::GetStatus("TEMP.DAT",fs);
          fs.m_mtime=0;
          fs.m_attribute = fs.m_attribute & !CFile::archive;
          CFile::SetStatus("TEMP.DAT",fs);
    

  2. Check to see whether the archive bit is clear instead of making a redundant call to clear it:

          CFile::GetStatus("TEMP.DAT",fs);
          if(fs.m_attribute & CFile::archive)
          {
    
            fs.m_attribute = fs.m_attribute & !CFile::archive;
            CFile::SetStatus("TEMP.DAT",fs);
          }
    
    

MORE INFORMATION

To duplicate this behavior, create a test file called TEMP.DAT and run the sample code below:

Sample Code

// Using the MS-DOS ATTRIB command, watch the archive bit toggle
// after each time you run the program.

   #define _DOS
   #include <afx.h>

   CFileStatus fs;

   void main(void) {
     CFile::GetStatus("TEMP.DAT",fs);
     fs.m_attribute = fs.m_attribute & !CFile::archive;
     CFile::SetStatus("TEMP.DAT",fs);
   }

This behavior does not occur with Visual C++ 32-bit Edition.

REFERENCES

The possible side effects of m_mtime on file attributes are discussed in the "Class Library Reference" for Visual C++, version 1.5, page 411.


Additional reference words: 7.00 1.00 1.50 2.00 2.50
KBCategory: kbprg kbprb
KBSubcategory: MfcFileIO
Keywords : kb16bitonly
Technology : kbMfc


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 22, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.