]> cygwin.com Git - cygwin-apps/setup.git/blame - find.cc
2001-11-13 Robert Collins <rbtcollins@hotmail.com>
[cygwin-apps/setup.git] / find.cc
CommitLineData
23c9e63c
DD
1/*
2 * Copyright (c) 2000, Red Hat, Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * A copy of the GNU General Public License can be found at
10 * http://www.gnu.org/
11 *
12 * Written by DJ Delorie <dj@cygnus.com>
13 *
14 */
15
16/* The purpose of this file is to doa recursive find on a given
17 directory, calling a given function for each file found. */
18
b24c88b3
RC
19#if 0
20static const char *cvsid =
21 "\n%%% $Id$\n";
22#endif
8507f105 23
23c9e63c
DD
24#include "win32.h"
25#include <stdio.h>
26#include <stdlib.h>
27
28#include "port.h"
29
b24c88b3 30static void (*for_each) (char *, unsigned int);
23c9e63c
DD
31static char dir[_MAX_PATH], *found_part;
32
33static int
34find_sub ()
35{
36 WIN32_FIND_DATA wfd;
37 HANDLE h;
38 char *end = dir + strlen (dir);
39 int rv = 0;
40
41 *end++ = '/';
42 strcpy (end, "*");
43
44 h = FindFirstFile (dir, &wfd);
45
46 if (h == INVALID_HANDLE_VALUE)
47 return 0;
48
b24c88b3
RC
49 do
50 {
51 if (strcmp (wfd.cFileName, ".") == 0
52 || strcmp (wfd.cFileName, "..") == 0)
53 continue;
23c9e63c 54
b24c88b3 55 strcpy (end, wfd.cFileName);
23c9e63c 56
b24c88b3
RC
57 if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
58 find_sub ();
59 else
60 {
61 for_each (found_part, wfd.nFileSizeLow);
62 rv++;
63 }
23c9e63c 64
b24c88b3
RC
65 }
66 while (FindNextFile (h, &wfd));
23c9e63c
DD
67
68 FindClose (h);
69 return rv;
70}
71
72int
b24c88b3 73find (const char *starting_dir, void (*_for_each) (char *, unsigned int))
23c9e63c
DD
74{
75 strcpy (dir, starting_dir);
76 for_each = _for_each;
77 found_part = dir + strlen (dir) + 1;
78
79 return find_sub ();
80}
This page took 0.031738 seconds and 5 git commands to generate.