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