home *** CD-ROM | disk | FTP | other *** search
/ kermit.columbia.edu / kermit.columbia.edu.tar / kermit.columbia.edu / bin / p205.zip / exesrc / dir.c < prev    next >
C/C++ Source or Header  |  1994-12-18  |  2KB  |  77 lines

  1. /*****************************************************************************/
  2. /*           Copyright (c) 1994 by Jyrki Salmi <jytasa@jyu.fi>             */
  3. /*        You may modify, recompile and distribute this file freely.         */
  4. /*****************************************************************************/
  5.  
  6. /*
  7.    A bit cleaner directory handling routines than the OS/2's DosFindFirst and
  8.    DosFindNext. Note that dir_find_close() should be called when done with
  9.    the directory listing.
  10. */
  11.  
  12. #include <stdio.h>
  13. #define INCL_DOSFILEMGR
  14. #include <os2.h>
  15. #include <string.h>
  16. #include <stdlib.h>
  17. #include "typedefs.h"
  18. #include "dir.h"
  19.  
  20. /* Finds a first file */
  21.  
  22. U32 dir_find_first(U8 *mask,
  23.            U32 attribute,
  24.            DIR_ENTRY *dir_entry) {
  25.  
  26.   U32 find_count = 1;
  27.   APIRET rc;
  28.  
  29.   if ((dir_entry->find_buf = malloc(sizeof(FILEFINDBUF3))) == NULL) {
  30.     fprintf(stderr, "Failed to allocate memory\n");
  31.     exit(1);
  32.   }
  33.   dir_entry->handle = HDIR_CREATE; /* HDIR_SYSTEM; */
  34.   rc = DosFindFirst(mask,
  35.             &dir_entry->handle,
  36.             attribute,
  37.             dir_entry->find_buf,
  38.             sizeof(FILEFINDBUF3),
  39.             &find_count,
  40.             FIL_STANDARD);
  41.   dir_entry->name = ((FILEFINDBUF3 *)dir_entry->find_buf)->achName;
  42.   dir_entry->size = (U32 *)&((FILEFINDBUF3 *)dir_entry->find_buf)->cbFile;
  43.   dir_entry->date = (U16 *)&((FILEFINDBUF3 *)dir_entry->find_buf)->fdateLastWrite;
  44.   dir_entry->time = (U16 *)&((FILEFINDBUF3 *)dir_entry->find_buf)->ftimeLastWrite;
  45.   dir_entry->attribute = &((FILEFINDBUF3 *)dir_entry->find_buf)->attrFile;
  46.   return(rc);
  47. }
  48.  
  49. /* Finds the next file */
  50.  
  51. U32 dir_find_next(DIR_ENTRY *dir_entry) {
  52.  
  53.   U32 find_count = 1;
  54.   APIRET rc;
  55.  
  56.   rc = DosFindNext(dir_entry->handle,
  57.            dir_entry->find_buf,
  58.            sizeof(FILEFINDBUF3),
  59.            &find_count);
  60.   dir_entry->name = ((FILEFINDBUF3 *)dir_entry->find_buf)->achName;
  61.   dir_entry->size = (U32 *)&((FILEFINDBUF3 *)dir_entry->find_buf)->cbFile;
  62.   dir_entry->date = (U16 *)&((FILEFINDBUF3 *)dir_entry->find_buf)->fdateLastWrite;
  63.   dir_entry->time = (U16 *)&((FILEFINDBUF3 *)dir_entry->find_buf)->ftimeLastWrite;
  64.   dir_entry->attribute = &((FILEFINDBUF3 *)dir_entry->find_buf)->attrFile;
  65.   return(rc);
  66. }
  67.  
  68. /* Ends the directory handling started by dir_find_first() */
  69.  
  70. U32 dir_find_close(DIR_ENTRY *dir_entry) {
  71.  
  72.   APIRET rc;
  73.  
  74.   rc = DosFindClose(dir_entry->handle);
  75.   return(rc);
  76. }
  77.