mountlist.o: mountlist.h
xgetcwd.o: pathmax.h
-# Prevent GNU make v3 from overflowing arg limit on SysV.
+# Tell versions [3.59,3.63) of GNU make not to export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:
Cambridge, MA 02139, USA. */
#ifdef HAVE_CONFIG_H
-#include "config.h"
+#include <config.h>
#endif
#include <errno.h>
#endif
/* Return the number of TOSIZE-byte blocks used by
- BLOCKS FROMSIZE-byte blocks, rounding up. */
+ BLOCKS FROMSIZE-byte blocks, rounding away from zero. */
static long
adjust_blocks (blocks, fromsize, tosize)
else if (fromsize > tosize) /* E.g., from 2048 to 512. */
return blocks * (fromsize / tosize);
else /* E.g., from 256 to 512. */
- return (blocks + 1) / (tosize / fromsize);
+ return (blocks + (blocks < 0 ? -1 : +1)) / (tosize / fromsize);
}
/* Fill in the fields of FSP with information about space usage for
+Wed Aug 25 21:40:00 EDT 1993
+
+ * cp.c: Add --parents as synonym for --path. Change --path to
+ --parents in comments. --path is deprecated.
+
+ * rm.c (clear_directory): Fix incorrect test for determining when
+ to reallocate buffer. Thanks to Ric Anderson <ric@CS.Arizona.EDU>.
+
+Fri Aug 13 17:19:52 1993 Jim Meyering (meyering@comco.com)
+
+ * fsusage (adjust_blocks): Round away from zero -- this matters
+ when computing the negative free-block count for disks that are
+ more than 100% full.
+
+ * mv.c (movefile): Use nested calls to stpcpy instead of sprintf.
+ (is_real_dir): New function.
+ (movefile): In addition to when dest is a directory, if dest has
+ a trailing `/' and source is not a directory, presume the target
+ is dest/`basename source`. This converts `mv a b/' to `mv a b/a'
+ when a is not a directory -- so the command will fail when a is a
+ non-directory and (b doesn't exist or b isn't a directory or a
+ symlink to a directory).
+
+ * ls.c (do_copy): Similarly, convert `cp a b/' to cp a b/a when
+ a is not a directory.
+
Wed Aug 4 17:43:18 1993 Jim Meyering (meyering@comco.com)
* ls.c (get_link_name): Don't ever use the stat field st_size as a
buffer size. Too many systems don't set it properly for mount points.
Instead, use a fixed-length buffer. From Michael Joosten
<joost@ori.CAdlab.DE>.
+ * cp.c (copy): Ditto.
Mon Jul 19 17:39:01 1993 Jim Meyering (meyering@comco.com)
+Major changes in release 3.9:
+* ls and cp can handle mount points on more systems
+* cp, mkdir, and rmdir long option --path renamed to --parents; --path
+ will still work for a while
+\f
Major changes in release 3.8:
* install isn't as likely to produce spurious errors
* avoid redundant compilations for `dir' and `vdir';
{"link", no_argument, NULL, 'l'},
{"no-dereference", no_argument, &flag_dereference, 0},
{"one-file-system", no_argument, &flag_one_file_system, 1},
+ {"parents", no_argument, &flag_path, 1},
{"path", no_argument, &flag_path, 1},
{"preserve", no_argument, &flag_preserve, 1},
{"recursive", no_argument, NULL, 'R'},
dst_path = xmalloc (strlen (dest) + strlen (arg) + 2);
stpcpy (stpcpy (stpcpy (dst_path, dest), "/"), arg);
- /* For --path, we have to make sure that the directory
+ /* For --parents, we have to make sure that the directory
dirname (dst_path) exists. We may have to create a few
leading directories. */
parent_exists = !make_path (dst_path,
}
else if (argc - optind == 2)
{
+ char *dst_path;
+ char *source;
+ struct stat source_stats;
+
if (flag_path)
usage ("when preserving paths, last argument must be a directory");
- return copy (argv[optind], dest, new_dst, 0, (struct dir_list *) 0);
+
+ source = argv[optind];
+
+ if (dest[strlen (dest) - 1] == '/'
+ && lstat (source, &source_stats) == 0
+ && !S_ISDIR (source_stats.st_mode))
+ {
+ char *base;
+
+ strip_trailing_slashes (source);
+ base = basename (source);
+ dst_path = (char *) alloca (strlen (dest) + 1 + strlen (base) + 1);
+ stpcpy (stpcpy (stpcpy (dst_path, dest), "/"), base);
+ }
+ else
+ {
+ dst_path = dest;
+ }
+
+ return copy (argv[optind], dst_path, new_dst, 0, (struct dir_list *) 0);
}
else
usage ("when copying multiple files, last argument must be a directory");
}
else
#ifdef S_ISLNK
-#ifdef _AIX
-#define LINK_BUF PATH_MAX
-#else
-#define LINK_BUF src_sb.st_size
-#endif
if (S_ISLNK (src_type))
{
- char *link_val = (char *) alloca (LINK_BUF + 1);
+ char link_val[PATH_MAX + 1];
int link_size;
- link_size = readlink (src_path, link_val, LINK_BUF);
+ link_size = readlink (src_path, link_val, sizeof (link_val) - 1);
if (link_size < 0)
{
error (0, errno, "cannot read symbolic link `%s'", src_path);
}
\f
/* Ensure that the parent directory of CONST_DIRPATH exists, for
- the --path option.
+ the --parents option.
SRC_OFFSET is the index in CONST_DIRPATH (which is a destination
path) of the beginning of the source directory name.
{
/* This element of the path does not exist. We must set
*new_dst and new->is_new_dir inside this loop because,
- for example, in the command `cp --path ../a/../b/c e_dir',
+ for example, in the command `cp --parents ../a/../b/c e_dir',
make_path creates only e_dir/../a if ./b already exists. */
*new_dst = 1;
new->is_new_dir = 1;
}
\f
/* Ensure that the parent directories of CONST_DST_PATH have the
- correct protections, for the --path option. This is done
+ correct protections, for the --parents option. This is done
after all copying has been completed, to allow permissions
that don't include user write/execute.
ATTR_LIST is a null-terminated linked list of structures that
indicates the end of the filename of each intermediate directory
in CONST_DST_PATH that may need to have its attributes changed.
- The command `cp --path --preserve a/b/c d/e_dir' changes the
+ The command `cp --parents --preserve a/b/c d/e_dir' changes the
attributes of the directories d/e_dir/a and d/e_dir/a/b to match
the corresponding source directories regardless of whether they
existed before the `cp' command was given.
/* Some automounters give incorrect st_size for mount points.
I can't think of a good workaround for it, though. */
- linksize = readlink (filename, linkbuf, sizeof (linkbuf));
+ linksize = readlink (filename, linkbuf, sizeof (linkbuf) - 1);
if (linksize < 0)
{
error (0, errno, "%s", filename);
void error ();
void strip_trailing_slashes ();
int eaccess_stat ();
+char *stpcpy ();
static int copy_reg ();
static int do_move ();
exit (errors);
}
+/* If PATH is an existing directory, return nonzero, else 0. */
+
+static int
+is_real_dir (path)
+ char *path;
+{
+ struct stat stats;
+
+ return lstat (path, &stats) == 0 && S_ISDIR (stats.st_mode);
+}
+
/* Move file SOURCE onto DEST. Handles the case when DEST is a directory.
Return 0 if successful, 1 if an error occurred. */
{
strip_trailing_slashes (source);
- if (isdir (dest))
+ if ((dest[strlen (dest) - 1] == '/' && !is_real_dir (source))
+ || isdir (dest))
{
/* Target is a directory; build full target filename. */
char *base;
base = basename (source);
new_dest = (char *) alloca (strlen (dest) + 1 + strlen (base) + 1);
- sprintf (new_dest, "%s/%s", dest, base);
+ stpcpy (stpcpy (stpcpy (new_dest, dest), "/"), base);
return do_move (source, new_dest);
}
else
int pathname_length; /* Length of `pathname'. */
ino_t *inode_space; /* Copy of directory's inodes. */
ino_t *inodep; /* Current entry in `inode_space'. */
- unsigned inode_size; /* Bytes allocated for `inode_space'. */
+ unsigned n_inodes_allocated; /* There is space for this many inodes
+ in `inode_space'. */
int err = 0; /* Return status. */
struct pathstack pathframe; /* New top of stack. */
struct pathstack *pp; /* Temporary. */
name_size = statp->st_size;
name_space = (char *) xmalloc (name_size);
- inode_size = statp->st_size;
- inode_space = (ino_t *) xmalloc (inode_size);
+ n_inodes_allocated = (statp->st_size + sizeof (ino_t) - 1) / sizeof (ino_t);
+ inode_space = (ino_t *) xmalloc (n_inodes_allocated * sizeof (ino_t));
do
{
}
namep = stpcpy (namep, dp->d_name) + 1;
- if (inodep == inode_space + inode_size)
+ if (inodep == inode_space + n_inodes_allocated)
{
ino_t *new_inode_space;
- inode_size += 1024;
- new_inode_space = (ino_t *) xrealloc (inode_space, inode_size);
+ n_inodes_allocated += 1024;
+ new_inode_space = (ino_t *) xrealloc (inode_space,
+ n_inodes_allocated * sizeof (ino_t));
inodep += new_inode_space - inode_space;
inode_space = new_inode_space;
}