~ubuntu-branches/ubuntu/vivid/cctools/vivid

« back to all changes in this revision

Viewing changes to dttools/src/sort_dir.h

  • Committer: Bazaar Package Importer
  • Author(s): Michael Hanke
  • Date: 2011-05-07 09:05:00 UTC
  • Revision ID: james.westby@ubuntu.com-20110507090500-lqpmdtwndor6e7os
Tags: upstream-3.3.2
ImportĀ upstreamĀ versionĀ 3.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Copyright (C) 2003-2004 Douglas Thain and the University of Wisconsin
 
3
Copyright (C) 2005- The University of Notre Dame
 
4
This software is distributed under the GNU General Public License.
 
5
See the file COPYING for details.
 
6
*/
 
7
 
 
8
#ifndef SORT_DIR_H
 
9
#define SORT_DIR_H
 
10
 
 
11
/** @file sort_dir.h Obtain a sorted directory listing.
 
12
    The prototype of @ref sort_dir is a little scary, but it is easy to use.
 
13
For example, to sort a given directory alphabetically:
 
14
 
 
15
<pre>
 
16
char **list;
 
17
int i;
 
18
 
 
19
sort_dir(dirname,&list,strcmp);
 
20
 
 
21
for(i=0;list[i];i++) printf("%s\n",list[i]);
 
22
 
 
23
sort_dir_free(list);
 
24
</pre>
 
25
*/
 
26
 
 
27
/** Obtain a sorted directory listing.
 
28
@param dirname The directory to list.
 
29
@param list A pointer to a doubly-indirect pointer, which will be filled with a list of strings.
 
30
The final item will be null.  This list must be freed with @ref sort_dir_free.
 
31
@param sort A pointer to a function to compare two strings, which must have the same semantics as <tt>strcmp</tt>
 
32
@return True on success, false on failure, setting errno appropriately.
 
33
*/
 
34
int sort_dir( const char *dirname, char ***list, int (*sort) ( const char *a, const char *b ) );
 
35
 
 
36
/** Free a sorted directory listing.
 
37
@param list The list to be freed.
 
38
*/
 
39
 
 
40
void sort_dir_free( char **list );
 
41
 
 
42
#endif