home *** CD-ROM | disk | FTP | other *** search
/ back2roots/padua / padua.7z / padua / uucp / LharcUUCP0_22.lha / LharcUUCP / source / ScanDir.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-08  |  3.6 KB  |  112 lines

  1. /*
  2.  *      $Filename: ScanDir.c $
  3.  *      $Revision: 0.5 $
  4.  *      $Date: 1993/12/08 17:15:53 $
  5.  *
  6.  *      Copyright (C) 1993 by Peter Simons <simons@peti.GUN.de>
  7.  *
  8.  *      This program is free software; you can redistribute it and/or
  9.  *      modify it under the terms of the GNU General Public License as
  10.  *      published by the Free Software Foundation; either version 2 of
  11.  *      the License, or (at your option) any later version.
  12.  *
  13.  *      This program is distributed in the hope that it will be useful,
  14.  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.  *      General Public License for more details.
  17.  *
  18.  *      You should have received a copy of the GNU General Public License
  19.  *      along with this program; if not, write to the Free Software
  20.  *      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  *
  22.  *      $Id: ScanDir.c,v 0.5 1993/12/08 17:15:53 simons Exp simons $
  23.  *
  24.  * ------------------------------ log history ----------------------------
  25.  * $Log: ScanDir.c,v $
  26.  * Revision 0.5  1993/12/08  17:15:53  simons
  27.  * InitScanDir() didn't reallocate the buffer in an overflow sitation,
  28.  * causing a system crash. :-) This is fixed now.
  29.  *
  30.  * Revision 0.4  1993/12/08  17:08:46  simons
  31.  * AmigaOS's filesystem used to have a bug in versions earlier than 40.x,
  32.  * that may cause corrupted blocks and even crashes if files are deleted
  33.  * or renamed while the ExNext()-scan is in progress. Therefore I changed
  34.  * the directory scan. Now, the directory is read completly and all names
  35.  * buffered.
  36.  * Thanks to Frank Bergknecht <frank@dino.dinoco.de> for drawing my
  37.  * attention to this.
  38.  *
  39.  * Revision 0.3  1993/12/04  21:55:27  simons
  40.  * ScanNextFil's buffers must be static, since the other routine accesses
  41.  * them.
  42.  *
  43.  * Revision 0.2  1993/12/04  21:52:40  simons
  44.  * The routines are working. ScanNextFile() buffers one the file currently
  45.  * locked and returns the previous one, so can I change the filename
  46.  * returned by the routine without losing the flow.
  47.  *
  48.  * Revision 0.1  1993/12/04  20:45:42  simons
  49.  * System dependant routines! Will need some work to port them.
  50.  */
  51.  
  52.  
  53. /************************************* includes ***********/
  54. #include <stdlib.h>
  55. #include <string.h>
  56. #include <dos.h>
  57.  
  58. /************************************* defines ************/
  59.  
  60. /************************************* prototypes *********/
  61.  
  62. /************************************* global variables ***/
  63. static const char __RCSId[] = "$Id: ScanDir.c,v 0.5 1993/12/08 17:15:53 simons Exp simons $";
  64.  
  65. static char *flnarray, *flnarray_current;
  66. static int flnarray_size = 2048;
  67.  
  68. extern int _OSERR;
  69.  
  70. /************************************* subroutines ********/
  71. int InitDirScan(char *flnpattern)
  72. {
  73.         while (flnarray = malloc(flnarray_size)) {
  74.                 if (getfnl(flnpattern,flnarray,flnarray_size,0) != -1) {
  75.                         flnarray_current = flnarray;
  76.                         return 1;
  77.                 }
  78.                 else {
  79.                         if (_OSERR)
  80.                                 return 0;
  81.                         else {
  82.                                 free(flnarray);
  83.                                 flnarray_size += 1024;
  84.                         }
  85.                 }
  86.         }
  87.         return 0;
  88. }
  89.  
  90.  
  91. char *ScanNextFile(void)
  92. {
  93.         char *name;
  94.  
  95.         if (!(*flnarray_current))
  96.                 return NULL;
  97.  
  98.         name = flnarray_current;
  99.         while (*(flnarray_current++))
  100.                 ;
  101.  
  102.         return name;
  103. }
  104.  
  105.  
  106. void EndDirScan(void)
  107. {
  108.         free(flnarray);
  109.         flnarray_size = 4096;
  110. }
  111.  
  112.