Hello, all:

OK, I have a test case under Watcom.  Unfortunately, IT IS NOT
sufficient to call FINDNEXT before doing the unlink.  If you do the
unlink even after the call to FINDNEXT, then files are still skipped.

The test program is:

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

void main()
  {
    struct _finddata_t  fileinfo;
    long                handle;
    int                 rc;
    char buffer[_MAX_PATH];
    char *status;

    int count = 0;

    /* Display name and size of "*.c" files */
    handle = _findfirst( "*.*", &fileinfo );
    rc = handle;
    while( rc != -1 )
    {
      printf( "%14s %10ld\n", fileinfo.name,
                              fileinfo.size );
      status=_fullpath(buffer,fileinfo.name,(size_t) _MAX_PATH);
      if (status != NULL)
        printf("%s\n",buffer);
      else
        printf("_fullpath failed\n");
 
      count++;
      rc = _findnext( handle, &fileinfo );
      if (unlink(buffer) != 0)
        printf("Unlink failed.\n");

    }
    _findclose( handle );
    printf("Found %i files.\n",count);
  }

This finds all 88 files in the directory if the unlink is commented
out. If the unlink is added, it only finds 79 files (or maybe 78
depending on whether unlink is called before or after _findnext).

This is the same behavior as FreeCOM is showing using Turbo C++.
Is it legal to modify the directory (deleting files) and expect
findnext to work?

Mark Bailey


> OK, I've done a bit more research on this problem.  The relevant
> portion of the delete function appears to be, removing some
> extraneous code:
> 
> if (FINDFIRST(fullname, &f, FA_ARCH)) {
>                               error_sfile_not_found(fullname);
>                       } else do {
>                               strcpy(p, f.ff_name);       /* Make the full 
> path */
> [...]
> 
>                               if(verbose && !optP)
>                                       displayString(TEXT_DELETE_FILE, 
> fullname);
>                               if(unlink(fullname) != 0) {
>                                       perror(fullname);   /* notify the user 
> */
>                               } else
>                                       ++count;
>                       } while (FINDNEXT(&f) == 0);
> 
> FINDFIRST and FINDNEXT are suppl calls to findfirst and findnext which
> invoke DOS calls (respectively):
> 
>       r.r_ax = 0x4e00;
>       rv = invokeDOS(&r);
> 
>       r.r_ax = 0x4f00;
>       rv = invokeDOS(&r);
> 
> Is it legal to do an invokeDOS on this interrupt on a non-existent file?
> The unlink is done before the findnext.  There's a test case I may 
> be able to duplicate...
> 


-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Freedos-user mailing list
Freedos-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freedos-user

Reply via email to