Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!rutgers!labrea!decwrl!sun!gorodish!guy From: guy%gorodish@Sun.COM (Guy Harris) Newsgroups: comp.unix.questions Subject: Re: System V Questions Message-ID: <25097@sun.uucp> Date: Fri, 7-Aug-87 01:42:16 EDT Article-I.D.: sun.25097 Posted: Fri Aug 7 01:42:16 1987 Date-Received: Sun, 9-Aug-87 02:45:08 EDT References: <8664@brl-adm.ARPA> Sender: news@sun.uucp Lines: 53 I tried mailing this, but got: ----- Transcript of session follows ----- Connected to wiscvm.wisc.edu: >>> RCPT To: <<< 550 Host 'LEHIIBM1.bitnet' Unknown 550 ... User unknown So: > 1. How does SysV do a rename? I.e, what is the equivalent of the > Berkeley rename system call? Well, you can rename non-directory files with: #include extern int errno; int rename(from, to) char *from; char *to; { if (unlink(to) < 0 && errno != ENOENT) return (-1); if (link(from, to) < 0) return (-1); return (unlink(from)); } (which will, of course, work on 4.[23]BSD also, but "rename" is preferable because it tries to eliminate the small windows in which there is either no file named by the path pointed to by "to" or where both the links "from" and "to" exist). If "to" or "from" are directories, this will "work" only if you're the super-user, and it won't work correctly; you'd have do make sure the directory referred to by "to" is empty, and then properly change the ".." link for the directory being renamed, if necessary. > 2. Has anyone written a ftruncate (again a Berkeley-ism) for SysV? Unfortunately, you can't. The only way to truncate a file in systems lacking something like "ftruncate" is to do a "creat" or an "open" with the O_TRUNC flag; to do this, you need the pathname of the file. Furthermore, this only truncates the file to zero length; the only way to shorten a file to a non-zero length is to copy the part to be retained to a temporary file and then copy it back to the original file. Guy Harris {ihnp4, decvax, seismo, decwrl, ...}!sun!guy guy@sun.com