516cbc6600
argument; POSIX allows this, even though the replacement lib/dirname.c (from glibc?) returns a strndup-ed strings *except* for the "." case. [mmm, possible memory leaks]. Instead, just implement most of guts of lib/dirname.c directly in assert_writeable(), always copy string, and always free it. This fixes ``mkid -f /some/path/to/id'' + Crank PKGREVISION.
52 lines
1.4 KiB
Text
52 lines
1.4 KiB
Text
$NetBSD: patch-ak,v 1.2 2002/06/21 12:26:32 lukem Exp $
|
|
|
|
--- src/mkid.c.orig Tue Jul 9 14:19:09 1996
|
|
+++ src/mkid.c
|
|
@@ -33,7 +33,6 @@
|
|
#include "hash.h"
|
|
#include "scanners.h"
|
|
#include "error.h"
|
|
-#include "xalloca.h"
|
|
#if HAVE_LIMITS_H
|
|
# include <limits.h>
|
|
#endif
|
|
@@ -304,12 +303,18 @@
|
|
{
|
|
if (errno == ENOENT)
|
|
{
|
|
- char const *dir_name = dirname (file_name);
|
|
- if (!dir_name || !*dir_name)
|
|
- dir_name = ".";
|
|
+ char *dir_name = strrchr (file_name, '/');
|
|
+ if (dir_name)
|
|
+ {
|
|
+ while (*--dir_name == '/')
|
|
+ ;
|
|
+ dir_name++;
|
|
+ }
|
|
+ dir_name = dir_name ? strndup (file_name, dir_name - file_name) : strdup(".");
|
|
if (access (dir_name, 06) < 0)
|
|
error (1, errno, _("can't create `%s' in `%s'"),
|
|
basename (file_name), dir_name);
|
|
+ free (dir_name);
|
|
}
|
|
else
|
|
error (1, errno, _("can't modify `%s'"), file_name);
|
|
@@ -363,7 +368,7 @@
|
|
{
|
|
if (fstat (fileno (source_FILE), &st) < 0)
|
|
{
|
|
- char *file_name = ALLOCA (char, PATH_MAX);
|
|
+ char file_name[PATH_MAX];
|
|
maybe_relative_file_name (file_name, flink, cw_dlink);
|
|
error (0, errno, _("can't stat `%s'"), file_name);
|
|
}
|
|
@@ -372,7 +377,7 @@
|
|
}
|
|
if (verbose_flag)
|
|
{
|
|
- char *file_name = ALLOCA (char, PATH_MAX);
|
|
+ char file_name[PATH_MAX];
|
|
maybe_relative_file_name (file_name, flink, cw_dlink);
|
|
printf ("%d: %s: %s", member->mf_index, lang->lg_name, file_name);
|
|
fflush (stdout);
|