home *** CD-ROM | disk | FTP | other *** search
- --- Makefile.rtr Fri Jan 31 19:59:13 1997
- +++ Makefile Tue Feb 4 17:18:22 1997
- @@ -1,10 +1,13 @@
- all: ren ren.1
-
- -ren: ren.c
- - $(CC) -o ren $(CFLAGS) ren.c -lbsd
- +ren: ren.c scandir.o
- + $(CC) -o ren $(CFLAGS) ren.c scandir.o
- install: all
- install -s ren <installdir>/bin
- install ren.1 <installsharedir>/man/man1
- +
- +scandir.o: scandir.c
- + $(CC) $(CFLAGS) -c scandir.c
-
- clean:
- rm -f core a.out ren ren.o
- --- scandir.c.rtr Tue Feb 4 17:12:16 1997
- +++ scandir.c Tue Feb 4 17:12:16 1997
- @@ -0,0 +1,136 @@
- +/*
- + * Copyright (c) 1983 Regents of the University of California.
- + * All rights reserved.
- + *
- + * Redistribution and use in source and binary forms are permitted provided
- + * that: (1) source distributions retain this entire copyright notice and
- + * comment, and (2) distributions including binaries display the following
- + * acknowledgement: ``This product includes software developed by the
- + * University of California, Berkeley and its contributors'' in the
- + * documentation or other materials provided with the distribution and in
- + * all advertising materials mentioning features or use of this software.
- + * Neither the name of the University nor the names of its contributors may
- + * be used to endorse or promote products derived from this software without
- + * specific prior written permission.
- + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
- + * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
- + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- + */
- +
- +/* Changes for SCO compatability by Ready-to-Run Software, Inc. */
- +
- +
- +#if defined(LIBC_SCCS) && !defined(lint)
- +static char sccsid[] = "@(#)scandir.c 5.9 (Berkeley) 6/24/90";
- +#endif /* LIBC_SCCS and not lint */
- +
- +#define NULL 0
- +#define bcopy(s1,s2,n) memcpy(s2,s1,n)
- +
- +/*
- + * Scan the directory dirname calling select to make a list of selected
- + * directory entries then sort using qsort and compare routine dcomp.
- + * Returns the number of entries and a pointer to a list of pointers to
- + * struct dirent (through namelist). Returns -1 if there were any errors.
- + */
- +
- +#include <sys/types.h>
- +#include <sys/stat.h>
- +#ifdef USE_NDIR
- +#include <sys/ndir.h>
- +
- +#define dirent direct
- +#else
- +#include <dirent.h>
- +#endif
- +
- +/*
- + * The DIRSIZ macro gives the minimum record length which will hold
- + * the directory entry. This requires the amount of space in struct dirent
- + * without the d_name field, plus enough space for the name with a terminating
- + * null byte (dp->d_namlen+1), rounded up to a 4 byte boundary.
- + * null byte (strlen(dp->d_name)+1), rounded up to a 4 byte boundary.
- + */
- +#undef DIRSIZ
- +#ifdef USE_NDIR
- +#define DIRSIZ(dp) \
- + ((sizeof (struct dirent) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3))
- +#else
- +#define DIRSIZ(dp) \
- + ((sizeof (struct dirent) - 1) + ((strlen((dp)->d_name)+1 + 3) &~ 3))
- +#endif
- +
- +scandir(dirname, namelist, select, dcomp)
- + char *dirname;
- + struct dirent ***namelist;
- + int (*select)(), (*dcomp)();
- +{
- + register struct dirent *d, *p, **names;
- + register int nitems;
- + struct stat stb;
- + long arraysz;
- + DIR *dirp;
- +
- + if ((dirp = opendir(dirname)) == NULL)
- + return(-1);
- + if (fstat(dirp->dd_fd, &stb) < 0)
- + return(-1);
- +
- + /*
- + * estimate the array size by taking the size of the directory file
- + * and dividing it by a multiple of the minimum size entry.
- + */
- + arraysz = (stb.st_size / 24);
- + names = (struct dirent **)malloc(arraysz * sizeof(struct dirent *));
- + if (names == NULL)
- + return(-1);
- +
- + nitems = 0;
- + while ((d = readdir(dirp)) != NULL) {
- + if (select != NULL && !(*select)(d))
- + continue; /* just selected names */
- + /*
- + * Make a minimum size copy of the data
- + */
- + p = (struct dirent *)malloc(DIRSIZ(d));
- + if (p == NULL)
- + return(-1);
- + p->d_ino = d->d_ino;
- + p->d_reclen = d->d_reclen;
- +#ifdef USE_NDIR
- + p->d_namlen = d->d_namlen;
- + bcopy(d->d_name, p->d_name, p->d_namlen + 1);
- +#else
- + bcopy(d->d_name, p->d_name, strlen(d->d_name) + 1);
- +#endif
- + /*
- + * Check to make sure the array has space left and
- + * realloc the maximum size.
- + */
- + if (++nitems >= arraysz) {
- + if (fstat(dirp->dd_fd, &stb) < 0)
- + return(-1); /* just might have grown */
- + arraysz = stb.st_size / 12;
- + names = (struct dirent **)realloc((char *)names,
- + arraysz * sizeof(struct dirent *));
- + if (names == NULL)
- + return(-1);
- + }
- + names[nitems-1] = p;
- + }
- + closedir(dirp);
- + if (nitems && dcomp != NULL)
- + qsort(names, nitems, sizeof(struct dirent *), dcomp);
- + *namelist = names;
- + return(nitems);
- +}
- +
- +/*
- + * Alphabetic order comparison routine for those who want it.
- + */
- +alphasort(d1, d2)
- + void *d1, *d2;
- +{
- + return(strcmp((*(struct dirent **)d1)->d_name,
- + (*(struct dirent **)d2)->d_name));
- +}
- --- ren.c.rtr Tue Feb 4 17:22:52 1997
- +++ ren.c Tue Feb 4 17:25:25 1997
- @@ -1,7 +1,8 @@
- #include <stdio.h>
- #include <unistd.h>
- #include <sys/file.h>
- -#include <sys/dir.h>
- +#include <dirent.h>
- +#define direct dirent
-
- #define MAXWILD 20
- #define MAXREP 40
- @@ -526,7 +527,8 @@
- tempnames[-(cur->ftorep)] :
- dot[cur->ftorep]->d_name);
- cur->status = DONE;
- - if (rename(fromname, cur->repname)) {
- + if (link(fromname, cur->repname) ||
- + unlink(fromname)) {
- fputs("Strange. Can not rename '", stderr);
- fputs(fromname, stderr);
- fputs("' to '", stderr);
-