home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / LIBSRC.ZOO / libsrc / local / closedir.c < prev    next >
Text File  |  1992-04-06  |  831b  |  38 lines

  1. #define INCL_DOSFILEMGR
  2. #include <os2.h>
  3.  
  4. #define __DIRENT_PRIVATE__
  5. #ifdef DEBUG
  6. #include <stdio.h>
  7. #endif
  8. #include <dirent.h>
  9. #include <errno.h>
  10.  
  11. ULONG Dos32FindClose() asm ("Dos32FindClose");
  12.  
  13. int closedir(dir)
  14.    DIR *dir;
  15. {
  16.      ULONG ret;
  17.  
  18.      /* This function frees allocated memory even if it is going to */
  19.      /* return an error code (e.g.: if DosFindClose fails).  If a */
  20.      /* program tries to correct the problem and call closedir() */
  21.      /* again, a memory error will result.  What is the correct */
  22.      /* behavior? */
  23.  
  24. #ifdef DEBUG
  25.      fprintf(stderr, "closedir: calling findclose\n");
  26. #endif 
  27.      ret = Dos32FindClose(dir->dirhandle);
  28.      free(dir->searchname);
  29.      free(dir);
  30.      if (ret != 0) {
  31.       errno = EBADF;
  32.       return -1;
  33.      } else
  34.       return 0;
  35. }
  36.  
  37.      
  38.