diff options
author | Anthony G. Basile <blueness@gentoo.org> | 2013-08-02 20:46:21 -0400 |
---|---|---|
committer | Anthony G. Basile <blueness@gentoo.org> | 2013-08-02 20:46:21 -0400 |
commit | a3cd924ecba40190703919285f5e2ef559d32ccd (patch) | |
tree | 344f2193c6d74d41bd6d34e828434350c4304d78 | |
parent | a57c8bba0d0c81cd3f884e173ff56f25b5946cf1 (diff) |
src/libudev/{strv,util}.{h,c}: reorder functions
We reorder the functions prototypes and definitions to match
upstream as in commit aa417a4d83999f6d7f092161d5c411b8cbce9977.
The order was lost when that commit was revert and the functions
re-introduced in later commits.
Preserving the order helps to better track upstream changes when
doing a diff between files.
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
-rw-r--r-- | src/libudev/strv.c | 11 | ||||
-rw-r--r-- | src/libudev/strv.h | 5 | ||||
-rw-r--r-- | src/libudev/util.c | 70 | ||||
-rw-r--r-- | src/libudev/util.h | 8 |
4 files changed, 43 insertions, 51 deletions
diff --git a/src/libudev/strv.c b/src/libudev/strv.c index 45fb6b24a2..3619701e9d 100644 --- a/src/libudev/strv.c +++ b/src/libudev/strv.c @@ -144,32 +144,23 @@ char **strv_new(const char *x, ...) { int strv_push(char ***l, char *value) { char **c; - char *v; unsigned n; if (!value) return 0; - v = strdup(value); - if (!v) - return -ENOMEM; - n = strv_length(*l); c = realloc(*l, sizeof(char*) * (n + 2)); - if (!c) { - free(v); if (!c) return -ENOMEM; - } - c[n] = v; c[n] = value; c[n+1] = NULL; *l = c; return 0; } - + int strv_extend(char ***l, const char *value) { char *v; int r; diff --git a/src/libudev/strv.h b/src/libudev/strv.h index ba2bc2f589..9fba94e566 100644 --- a/src/libudev/strv.h +++ b/src/libudev/strv.h @@ -36,9 +36,10 @@ static inline void strv_freep(char ***l) { char **strv_copy(char * const *l); unsigned strv_length(char * const *l) _pure_; -char **strv_remove(char **l, const char *s); -int strv_push(char ***l, char *value); int strv_extend(char ***l, const char *value); +int strv_push(char ***l, char *value); + +char **strv_remove(char **l, const char *s); char **strv_uniq(char **l); char **strv_new(const char *x, ...) _sentinel_; diff --git a/src/libudev/util.c b/src/libudev/util.c index 5abf6589af..10a786368e 100644 --- a/src/libudev/util.c +++ b/src/libudev/util.c @@ -545,6 +545,41 @@ char *strappend(const char *s, const char *suffix) { return strnappend(s, suffix, suffix ? strlen(suffix) : 0); } +char hexchar(int x) { + static const char table[16] = "0123456789abcdef"; + + return table[x & 15]; +} + +char *xescape(const char *s, const char *bad) { + char *r, *t; + const char *f; + + /* Escapes all chars in bad, in addition to \ and all special + * chars, in \xFF style escaping. May be reversed with + * cunescape. */ + + r = new(char, strlen(s) * 4 + 1); + if (!r) + return NULL; + + for (f = s, t = r; *f; f++) { + + if ((*f < ' ') || (*f >= 127) || + (*f == '\\') || strchr(bad, *f)) { + *(t++) = '\\'; + *(t++) = 'x'; + *(t++) = hexchar(*f >> 4); + *(t++) = hexchar(*f); + } else + *(t++) = *f; + } + + *t = 0; + + return r; +} + _pure_ static bool ignore_file_allow_backup(const char *filename) { assert(filename); @@ -999,12 +1034,6 @@ int fd_inc_sndbuf(int fd, size_t n) { return 1; } -char hexchar(int x) { - static const char table[16] = "0123456789abcdef"; - - return table[x & 15]; -} - bool in_initrd(void) { static __thread int saved = -1; struct statfs s; @@ -1051,32 +1080,3 @@ void *xbsearch_r(const void *key, const void *base, size_t nmemb, size_t size, } return NULL; } - -char *xescape(const char *s, const char *bad) { - char *r, *t; - const char *f; - - /* Escapes all chars in bad, in addition to \ and all special - * chars, in \xFF style escaping. May be reversed with - * cunescape. */ - - if (!(r = new(char, strlen(s)*4+1))) - return NULL; - - for (f = s, t = r; *f; f++) { - - if (*f < ' ' || *f >= 127 || - *f == '\\' || strchr(bad, *f)) { - *(t++) = '\\'; - *(t++) = 'x'; - *(t++) = hexchar(*f >> 4); - *(t++) = hexchar(*f); - } else - *(t++) = *f; - } - - *t = 0; - - return r; -} - diff --git a/src/libudev/util.h b/src/libudev/util.h index f7058895c0..7b6571ab10 100644 --- a/src/libudev/util.h +++ b/src/libudev/util.h @@ -131,6 +131,10 @@ char *strnappend(const char *s, const char *suffix, size_t length); char *truncate_nl(char *s); +char hexchar(int x) _const_; + +char *xescape(const char *s, const char *bad); + bool dirent_is_file_with_suffix(const struct dirent *de, const char *suffix) _pure_; bool ignore_file(const char *filename) _pure_; @@ -235,8 +239,6 @@ extern char **saved_argv; int fd_inc_sndbuf(int fd, size_t n); -char hexchar(int x); - bool in_initrd(void); static inline void freep(void *p) { @@ -274,8 +276,6 @@ void *xbsearch_r(const void *key, const void *base, size_t nmemb, size_t size, int (*compar) (const void *, const void *, void *), void *arg); -char *xescape(const char *s, const char *bad); - static inline void _reset_errno_(int *saved_errno) { errno = *saved_errno; } |