glob-util: rework safe_glob()
Currently, callers of safe_glob() set an empty glob_t or glob_t with opendir func, and all other components are always zero. So, let's introduce safe_glob_full() which optionally takes opendir function, rather than glob_t, and returns result strv, rather than storing results in glob_t. Also, introduce safe_glob() which is a trivial wrapper of safe_glob_full() without opendir func. No functional change, just refactoring.
This commit is contained in:
@@ -5,11 +5,15 @@
|
||||
|
||||
#include "forward.h"
|
||||
|
||||
/* Note: this function modifies pglob to set various functions. */
|
||||
int safe_glob(const char *path, int flags, glob_t *pglob);
|
||||
typedef DIR* (*opendir_t)(const char *);
|
||||
|
||||
int safe_glob_full(const char *path, int flags, opendir_t opendir_func, char ***ret);
|
||||
static inline int safe_glob(const char *path, int flags, char ***ret) {
|
||||
return safe_glob_full(path, flags, NULL, ret);
|
||||
}
|
||||
|
||||
/* Note: which match is returned depends on the implementation/system and not guaranteed to be stable */
|
||||
int glob_first(const char *path, char **ret_first);
|
||||
int glob_first(const char *path, char **ret);
|
||||
#define glob_exists(path) glob_first(path, NULL)
|
||||
int glob_extend(char ***strv, const char *path, int flags);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user