]> cygwin.com Git - cygwin-apps/setup.git/blame - find.cc
2002-04-27 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
3c054baf
RC
30#include "String++.h"
31#include "find.h"
32
23c9e63c
DD
33static char dir[_MAX_PATH], *found_part;
34
35static int
3c054baf 36find_sub (void (*for_each) (char *, unsigned int))
23c9e63c
DD
37{
38 WIN32_FIND_DATA wfd;
39 HANDLE h;
40 char *end = dir + strlen (dir);
41 int rv = 0;
42
43 *end++ = '/';
44 strcpy (end, "*");
45
46 h = FindFirstFile (dir, &wfd);
47
48 if (h == INVALID_HANDLE_VALUE)
49 return 0;
50
b24c88b3
RC
51 do
52 {
53 if (strcmp (wfd.cFileName, ".") == 0
54 || strcmp (wfd.cFileName, "..") == 0)
55 continue;
23c9e63c 56
b24c88b3 57 strcpy (end, wfd.cFileName);
23c9e63c 58
b24c88b3 59 if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
3c054baf 60 find_sub (for_each);
b24c88b3
RC
61 else
62 {
63 for_each (found_part, wfd.nFileSizeLow);
64 rv++;
65 }
23c9e63c 66
b24c88b3
RC
67 }
68 while (FindNextFile (h, &wfd));
23c9e63c
DD
69
70 FindClose (h);
71 return rv;
72}
73
74int
3c054baf 75find (String const &starting_dir, void (*_for_each) (char *, unsigned int))
23c9e63c 76{
3c054baf 77 strcpy (dir, starting_dir.cstr_oneuse());
23c9e63c
DD
78 found_part = dir + strlen (dir) + 1;
79
3c054baf 80 return find_sub (_for_each);
23c9e63c 81}
This page took 0.038818 seconds and 5 git commands to generate.