home *** CD-ROM | disk | FTP | other *** search
- /*
- * $Filename: ScanDir.c $
- * $Revision: 0.5 $
- * $Date: 1993/12/08 17:15:53 $
- *
- * Copyright (C) 1993 by Peter Simons <simons@peti.GUN.de>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * $Id: ScanDir.c,v 0.5 1993/12/08 17:15:53 simons Exp simons $
- *
- * ------------------------------ log history ----------------------------
- * $Log: ScanDir.c,v $
- * Revision 0.5 1993/12/08 17:15:53 simons
- * InitScanDir() didn't reallocate the buffer in an overflow sitation,
- * causing a system crash. :-) This is fixed now.
- *
- * Revision 0.4 1993/12/08 17:08:46 simons
- * AmigaOS's filesystem used to have a bug in versions earlier than 40.x,
- * that may cause corrupted blocks and even crashes if files are deleted
- * or renamed while the ExNext()-scan is in progress. Therefore I changed
- * the directory scan. Now, the directory is read completly and all names
- * buffered.
- * Thanks to Frank Bergknecht <frank@dino.dinoco.de> for drawing my
- * attention to this.
- *
- * Revision 0.3 1993/12/04 21:55:27 simons
- * ScanNextFil's buffers must be static, since the other routine accesses
- * them.
- *
- * Revision 0.2 1993/12/04 21:52:40 simons
- * The routines are working. ScanNextFile() buffers one the file currently
- * locked and returns the previous one, so can I change the filename
- * returned by the routine without losing the flow.
- *
- * Revision 0.1 1993/12/04 20:45:42 simons
- * System dependant routines! Will need some work to port them.
- */
-
-
- /************************************* includes ***********/
- #include <stdlib.h>
- #include <string.h>
- #include <dos.h>
-
- /************************************* defines ************/
-
- /************************************* prototypes *********/
-
- /************************************* global variables ***/
- static const char __RCSId[] = "$Id: ScanDir.c,v 0.5 1993/12/08 17:15:53 simons Exp simons $";
-
- static char *flnarray, *flnarray_current;
- static int flnarray_size = 2048;
-
- extern int _OSERR;
-
- /************************************* subroutines ********/
- int InitDirScan(char *flnpattern)
- {
- while (flnarray = malloc(flnarray_size)) {
- if (getfnl(flnpattern,flnarray,flnarray_size,0) != -1) {
- flnarray_current = flnarray;
- return 1;
- }
- else {
- if (_OSERR)
- return 0;
- else {
- free(flnarray);
- flnarray_size += 1024;
- }
- }
- }
- return 0;
- }
-
-
- char *ScanNextFile(void)
- {
- char *name;
-
- if (!(*flnarray_current))
- return NULL;
-
- name = flnarray_current;
- while (*(flnarray_current++))
- ;
-
- return name;
- }
-
-
- void EndDirScan(void)
- {
- free(flnarray);
- flnarray_size = 4096;
- }
-
-