Skip to content

Commit

Permalink
string_utils: add remove_trailing_slashes()
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
  • Loading branch information
Christian Brauner committed Aug 23, 2018
1 parent 9809fcf commit 10846a6
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
7 changes: 0 additions & 7 deletions src/lxc/initutils.c
Expand Up @@ -217,13 +217,6 @@ const char *lxc_global_config_value(const char *option_name)
return values[i];
}

extern void remove_trailing_slashes(char *p)
{
int l = strlen(p);
while (--l >= 0 && (p[l] == '/' || p[l] == '\n'))
p[l] = '\0';
}

/*
* Sets the process title to the specified title. Note that this may fail if
* the kernel doesn't support PR_SET_MM_MAP (kernels <3.18).
Expand Down
7 changes: 4 additions & 3 deletions src/lxc/initutils.h
Expand Up @@ -24,19 +24,21 @@
#ifndef __LXC_INITUTILS_H
#define __LXC_INITUTILS_H

#include "config.h"

#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/mount.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>

#include "config.h"
#include "string_utils.h"

#define DEFAULT_VG "lxc"
#define DEFAULT_THIN_POOL "lxc"
Expand Down Expand Up @@ -70,7 +72,6 @@ struct prctl_mm_map {

extern const char *lxc_global_config_value(const char *option_name);

extern void remove_trailing_slashes(char *p);
extern int setproctitle(char *title);

#endif /* __LXC_INITUTILS_H */
7 changes: 7 additions & 0 deletions src/lxc/string_utils.c
Expand Up @@ -978,3 +978,10 @@ int lxc_is_line_empty(const char *line)
return 0;
return 1;
}

void remove_trailing_slashes(char *p)
{
int l = strlen(p);
while (--l >= 0 && (p[l] == '/' || p[l] == '\n'))
p[l] = '\0';
}
1 change: 1 addition & 0 deletions src/lxc/string_utils.h
Expand Up @@ -111,5 +111,6 @@ extern int lxc_char_right_gc(const char *buffer, size_t len);
extern char *lxc_trim_whitespace_in_place(char *buffer);

extern int lxc_is_line_empty(const char *line);
extern void remove_trailing_slashes(char *p);

#endif /* __LXC_STRING_UTILS_H */

0 comments on commit 10846a6

Please sign in to comment.