chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
shared: inline trivial auto-cleanup functions
[elogind.git]
/
src
/
shared
/
util.c
diff --git
a/src/shared/util.c
b/src/shared/util.c
index e643cd367c95b98b8f31fbe811b00b3a54370e77..594f8de755c7a767b698187b50b67fe68e0d7185 100644
(file)
--- a/
src/shared/util.c
+++ b/
src/shared/util.c
@@
-1325,16
+1325,24
@@
char *bus_path_escape(const char *s) {
assert(s);
/* Escapes all chars that D-Bus' object path cannot deal
assert(s);
/* Escapes all chars that D-Bus' object path cannot deal
- * with. Can be reverse with bus_path_unescape() */
+ * with. Can be reverse with bus_path_unescape(). We special
+ * case the empty string. */
- if (!(r = new(char, strlen(s)*3+1)))
+ if (*s == 0)
+ return strdup("_");
+
+ r = new(char, strlen(s)*3 + 1);
+ if (!r)
return NULL;
for (f = s, t = r; *f; f++) {
return NULL;
for (f = s, t = r; *f; f++) {
+ /* Escape everything that is not a-zA-Z0-9. We also
+ * escape 0-9 if it's the first character */
+
if (!(*f >= 'A' && *f <= 'Z') &&
!(*f >= 'a' && *f <= 'z') &&
if (!(*f >= 'A' && *f <= 'Z') &&
!(*f >= 'a' && *f <= 'z') &&
- !(*f >= '0' && *f <= '9')) {
+ !(
f > s &&
*f >= '0' && *f <= '9')) {
*(t++) = '_';
*(t++) = hexchar(*f >> 4);
*(t++) = hexchar(*f);
*(t++) = '_';
*(t++) = hexchar(*f >> 4);
*(t++) = hexchar(*f);
@@
-1352,7
+1360,12
@@
char *bus_path_unescape(const char *f) {
assert(f);
assert(f);
- if (!(r = strdup(f)))
+ /* Special case for the empty string */
+ if (streq(f, "_"))
+ return strdup("");
+
+ r = new(char, strlen(f) + 1);
+ if (!r)
return NULL;
for (t = r; *f; f++) {
return NULL;
for (t = r; *f; f++) {
@@
-3594,8
+3607,8
@@
void execute_directory(const char *directory, DIR *d, char *argv[]) {
assert(directory);
assert(directory);
- /* Executes all binaries in a directory in parallel and
waits
- *
until all they all finished
. */
+ /* Executes all binaries in a directory in parallel and
+ *
waits for them to finish
. */
if (!d) {
if (!(_d = opendir(directory))) {
if (!d) {
if (!(_d = opendir(directory))) {
@@
-5224,10
+5237,6
@@
int get_shell(char **_sh) {
return 0;
}
return 0;
}
-void freep(void *p) {
- free(*(void**) p);
-}
-
void fclosep(FILE **f) {
if (*f)
fclose(*f);
void fclosep(FILE **f) {
if (*f)
fclose(*f);
@@
-5248,10
+5257,6
@@
void closedirp(DIR **d) {
closedir(*d);
}
closedir(*d);
}
-void umaskp(mode_t *u) {
- umask(*u);
-}
-
bool filename_is_safe(const char *p) {
if (isempty(p))
bool filename_is_safe(const char *p) {
if (isempty(p))