source: trunk/third/patch/rename.c @ 9069

Revision 9069, 1.3 KB checked in by ghudson, 28 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r9068, which included commits to RCS files with non-trunk default branches.
Line 
1/* rename.c -- BSD compatible directory function for System V
2   Copyright (C) 1988, 1990, 1992 Free Software Foundation, Inc.
3
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU General Public License as published by
6   the Free Software Foundation; either version 2, or (at your option)
7   any later version.
8
9   This program is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   GNU General Public License for more details.
13
14   You should have received a copy of the GNU General Public License
15   along with this program; if not, write to the Free Software
16   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
17
18#include <sys/types.h>
19#include <sys/stat.h>
20#include <errno.h>
21#ifndef STDC_HEADERS
22extern int errno;
23#endif
24
25/* Rename file FROM to file TO.
26   Return 0 if successful, -1 if not. */
27
28int
29rename (from, to)
30     char *from;
31     char *to;
32{
33  struct stat from_stats;
34
35  if (stat (from, &from_stats))
36    return -1;
37
38  if (unlink (to) && errno != ENOENT)
39    return -1;
40
41  if (link (from, to))
42    return -1;
43
44  if (unlink (from) && errno != ENOENT)
45    {
46      unlink (to);
47      return -1;
48    }
49
50  return 0;
51}
Note: See TracBrowser for help on using the repository browser.