mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-03 05:18:29 +03:00
Eliminate uses of strdup+basename. Use last_path_component instead.
* 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.
This commit is contained in:
parent
bbcd24607c
commit
6c35e3c84c
@ -1,4 +1,5 @@
|
||||
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.
|
||||
|
@ -38,6 +38,7 @@
|
||||
../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
|
||||
|
@ -80,6 +80,7 @@ SOURCES =\
|
||||
misc/lvm-string.c \
|
||||
misc/lvm-wrappers.c \
|
||||
misc/timestamp.c \
|
||||
misc/util.c \
|
||||
mm/memlock.c \
|
||||
report/report.c \
|
||||
striped/striped.c \
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include "intl.h"
|
||||
#include "lvm-types.h"
|
||||
#include "lvm-wrappers.h"
|
||||
#include "util.h"
|
||||
|
||||
#include <libdevmapper.h>
|
||||
|
||||
|
24
lib/misc/util.c
Normal file
24
lib/misc/util.c
Normal file
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
20
lib/misc/util.h
Normal file
20
lib/misc/util.h
Normal file
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* 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
|
@ -32,6 +32,8 @@
|
||||
#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 */
|
||||
@ -45,7 +47,7 @@ struct fsinfo {
|
||||
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. */
|
||||
|
@ -479,18 +479,15 @@ void lvm_register_commands(void)
|
||||
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;
|
||||
|
||||
@ -1138,14 +1135,13 @@ static void _exec_lvm1_command(char **argv)
|
||||
|
||||
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") &&
|
||||
@ -1160,8 +1156,6 @@ int lvm2_main(int argc, char **argv, unsigned is_static)
|
||||
unsetenv("LVM_DID_EXEC");
|
||||
}
|
||||
|
||||
free(namebase);
|
||||
|
||||
if (!(cmd = init_lvm(is_static)))
|
||||
return -1;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user