goer@sophist.uucp (Richard Goerwitz) (03/16/90)
Archive-name: xenix-rename/15-Mar-90 Original-posting-by: goer@sophist.uucp (Richard Goerwitz) Original-subject: Re: LHARC, SCO XENIX Reposted-by: emv@math.lsa.umich.edu (Edward Vielmetti) [This is an experimental alt.sources re-posting from the newsgroup(s) comp.unix.xenix,comp.sources.d,comp.sources.wanted. Comments on this service to emv@math.lsa.umich.edu (Edward Vielmetti).] In article <859@stsim.ocs.com> glenn@stsim (glenn ford) writes: >I have LHARC working under SCO Xenix 2.3 pretty much except for one tiny >problem.... Any help as to where to find "rename" in the SCO libraries >or a suitable replacement would be GREATLY appreciated.... This keeps coming up, so I don't think it will be too much of an imposi- tion on the net to post something I found a while back, and which has proven useful on several occasions. Note that I am NOT the author: #!/bin/sh # shar: Shell Archiver (v1.22) # # Run the following text with /bin/sh to create: # rename.c # sed 's/^X//' << 'SHAR_EOF' > rename.c && X/* X * $Author: chip $ $Date: 89/06/29 13:02:31 $ X * $Header: rename.c,v 1.1 89/06/29 13:02:31 chip Exp $ X * $Revision: 1.1 $ X */ X X/* X * Rename system call -- Replacement for Berzerkeley 4.2 rename system X * call that is missing in Xenix. X * X * By Marc Frajola and Chris Paris. X * Directory hack by Chip Salzenberg. X */ X X#include <stdio.h> X#include <sys/types.h> X#include <sys/stat.h> X#include <signal.h> X#include <errno.h> X Xrename(src,dest) X char *src; /* Source file to rename */ X char *dest; /* Name for renamed file */ X{ X int status; /* Status returned from link system call */ X struct stat stbuf; /* Buffer for statting destination file */ X X /* Find out what the destination is: */ X status = stat(dest,&stbuf); X if (status >= 0) { X /* See if the file is a regular file; if not, return error: */ X if ((stbuf.st_mode & S_IFMT) != S_IFREG) { X return(-1); X } X } X X /* Unlink destination since it is a file: */ X unlink(dest); X X /* Find out what the source is: */ X status = stat(src,&stbuf); X if (status < 0) X return -1; X if ((stbuf.st_mode & S_IFMT) == S_IFDIR) X { X /* Directory hack for SCO Xenix */ X X static char mvdir[] = "/usr/lib/mv_dir"; X void (*oldsigcld)(); X int pid; X X oldsigcld = signal(SIGCLD, SIG_DFL); X while ((pid = fork()) == -1) X { X if (errno != EAGAIN) X return -1; X sleep(5); X } X if (pid == 0) X { X execl(mvdir, mvdir, src, dest, (char *) 0); X perror(mvdir); X exit(1); X } X if (wait(&status) != pid) X { X fprintf(stderr, "rename: wait failure\n"); X status = -1; X } X (void) signal(SIGCLD, oldsigcld); X } X else X { X /* Link source to destination file: */ X status = link(src,dest); X if (status != 0) { X return(-1); X } X status = unlink(src); X } X return((status == 0) ? 0 : (-1)); X} SHAR_EOF chmod 0644 rename.c || echo "restore of rename.c fails" exit 0 -Richard L. Goerwitz goer%sophist@uchicago.bitnet goer@sophist.uchicago.edu rutgers!oddjob!gide!sophist!goer