* lib/misc/util.c, lib/misc/util.h (last_path_component): New files.
* lib/Makefile.in (SOURCES): Add misc/util.c.
* lib/misc/lib.h: Include "util.h".
* tools/fsadm/fsadm.c: Include "util.h". (_usage): Use last_path_component,
not basename.
* tools/lvmcmdline.c (_find_command, lvm2_main): Likewise.
* include/.symlinks: Add lib/misc/util.h.
Version 2.02.28 -
+ Eliminate uses of strdup+basename. Use last_path_component instead.
Use gcc's printf attribute wherever possible.
In _line_append, use "sizeof buf - 1" rather than equivalent "4095"
Introduce is_same_inode macro, now including a comparison of st_dev.
../lib/misc/configure.h
../lib/misc/crc.h
../lib/misc/intl.h
+../lib/misc/util.h
../lib/misc/lib.h
../lib/misc/lvm-exec.h
../lib/misc/lvm-file.h
misc/lvm-string.c \
misc/lvm-wrappers.c \
misc/timestamp.c \
+ misc/util.c \
mm/memlock.c \
report/report.c \
striped/striped.c \
#include "intl.h"
#include "lvm-types.h"
#include "lvm-wrappers.h"
+#include "util.h"
#include <libdevmapper.h>
--- /dev/null
+/*
+ * Copyright (C) 2007 Red Hat, Inc. All rights reserved.
+ *
+ * This file is part of LVM2.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU General Public License v.2.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/*
+ * Return the address of the last file name component of NAME.
+ * If NAME ends in a slash, return the empty string.
+ */
+char *last_path_component(char const *name)
+{
+ char const *slash = strrchr (name, '/');
+ char const *res = slash ? slash + 1 : name;
+ return (char *) res;
+}
--- /dev/null
+/*
+ * Copyright (C) 2007 Red Hat, Inc. All rights reserved.
+ *
+ * This file is part of LVM2.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU General Public License v.2.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef _LVM_UTIL_H
+#define _LVM_UTIL_H
+
+char *last_path_component(char const *name);
+
+#endif
#include <sys/mount.h>
#include <sys/vfs.h>
+#include "util.h"
+
#define log_error(str, x...) fprintf(stderr, "%s(%u): " str "\n", __FILE__, __LINE__, x)
/* Filesystem related information */
static void _usage(const char *cmd)
{
log_error("Usage: %s [check <filesystem> | resize <filesystem> <size>]",
- basename(cmd));
+ last_path_component(cmd));
}
/* FIXME Make this more robust - /proc, multiple mounts, TMPDIR + security etc. */
static struct command *_find_command(const char *name)
{
int i;
- char *namebase, *base;
+ char *base;
- namebase = strdup(name);
- base = basename(namebase);
+ base = last_path_component(name);
for (i = 0; i < _cmdline.num_commands; i++) {
if (!strcmp(base, _cmdline.commands[i].name))
break;
}
- free(namebase);
-
if (i >= _cmdline.num_commands)
return 0;
int lvm2_main(int argc, char **argv, unsigned is_static)
{
- char *namebase, *base;
+ char *base;
int ret, alias = 0;
struct cmd_context *cmd;
_close_stray_fds();
- namebase = strdup(argv[0]);
- base = basename(namebase);
+ base = last_path_component(argv[0]);
while (*base == '/')
base++;
if (strcmp(base, "lvm") && strcmp(base, "lvm.static") &&
unsetenv("LVM_DID_EXEC");
}
- free(namebase);
-
if (!(cmd = init_lvm(is_static)))
return -1;