2 * This file is part of Resource Organizer.
4 * Copyright (C) 2014 Nikita Zlobin <nick87720z@gmail.com>
6 * Resource Organizer is free software: you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * Resource Organizer is distributed in the hope that it will be
12 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Resource Organizer. If not, see
18 * <http://www.gnu.org/licenses/>.
26 #include <sys/types.h>
29 #include <search-so.h>
31 /* Search just the one directory. */
35 FilePathHandlerFunc cb_func
37 char * fileName
= NULL
;
41 struct dirent
* dirEntry
;
43 lDirLength
= strlen (dirname
);
44 if (!lDirLength
) return;
45 if (dirname
[lDirLength
- 1] == '/')
50 dir
= opendir (dirname
);
53 size_t size
= 0, new_size
;
55 dirEntry
= readdir (dir
);
62 /* Skip special names */
63 if (strcmp (dirEntry
->d_name
, "..") == 0 || strcmp (dirEntry
->d_name
, ".") == 0)
68 + strlen (dirEntry
->d_name
)
72 fileName
= realloc (fileName
, (size
= new_size
));
74 strcpy (fileName
, dirname
);
76 strcat (fileName
, "/");
77 strcat (fileName
, dirEntry
->d_name
);
79 /* Recursive search */
80 if (dirEntry
->d_type
== DT_DIR
)
82 dirIterate (fileName
, cb_func
);
86 /* We've successfully found a ladspa_descriptor function. Pass
87 * it to the callback function. */
92 /*****************************************************************************/
96 FilePathHandlerFunc cb_func
100 const char * pcStart
;
103 pcPath
= getenv (pathEnv
);
107 "Warning: You do not have a LADSPA_PATH "
108 "environment variable set.\n" );
112 pcEnd
= pcStart
= pcPath
;
114 while (*pcEnd
!= ':' && *pcEnd
!= '\0')
117 size_t size
= 0, new_size
, len
;
118 len
= pcEnd
- pcStart
;
122 buf
= realloc (buf
, (size
= new_size
));
125 strncpy (buf
, pcStart
, len
);
128 dirIterate (buf
, cb_func
);
130 if (* pcEnd
== ':') pcStart
= ++pcEnd
;
138 /*****************************************************************************/