]> cygwin.com Git - cygwin-apps/setup.git/blob - find.cc
b37e14660cb0f711d3feae114a4e6db13c61ec3f
[cygwin-apps/setup.git] / find.cc
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
19 #if 0
20 static const char *cvsid =
21 "\n%%% $Id$\n";
22 #endif
23
24 #include "win32.h"
25 #include <stdio.h>
26 #include <stdlib.h>
27
28 #include "port.h"
29
30 #include "String++.h"
31 #include "find.h"
32
33 static char dir[_MAX_PATH];
34
35 static int
36 find_sub (void (*for_each) (char *, unsigned int))
37 {
38 WIN32_FIND_DATA wfd;
39 HANDLE h;
40 char *end = dir + strlen (dir);
41 int rv = 0;
42
43 strcpy (end, "\\*");
44
45 h = FindFirstFile (dir, &wfd);
46
47 if (h == INVALID_HANDLE_VALUE)
48 return 0;
49
50 do
51 {
52 if (strcmp (wfd.cFileName, ".") == 0
53 || strcmp (wfd.cFileName, "..") == 0)
54 continue;
55
56 *end = '\\';
57 strcpy (end + 1, wfd.cFileName);
58
59 if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
60 find_sub (for_each);
61 else
62 {
63 for_each (dir, wfd.nFileSizeLow);
64 rv++;
65 }
66
67 }
68 while (FindNextFile (h, &wfd));
69
70 FindClose (h);
71 return rv;
72 }
73
74 int
75 find (String const &starting_dir, void (*_for_each) (char *, unsigned int))
76 {
77 strcpy (dir, starting_dir.cstr_oneuse());
78
79 return find_sub (_for_each);
80 }
This page took 0.036651 seconds and 4 git commands to generate.