~ubuntu-branches/ubuntu/utopic/binkd/utopic-proposed

« back to all changes in this revision

Viewing changes to unix/rename.c

  • Committer: Bazaar Package Importer
  • Author(s): Marco d'Itri
  • Date: 2002-03-24 22:52:25 UTC
  • Revision ID: james.westby@ubuntu.com-20020324225225-7ru6itlapn03nl35
Tags: upstream-0.9.5a
ImportĀ upstreamĀ versionĀ 0.9.5a

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * $Id: rename.c,v 2.0 2001/01/10 12:12:40 gul Exp $
 
3
 *
 
4
 * Revision history:
 
5
 * $Log: rename.c,v $
 
6
 * Revision 2.0  2001/01/10 12:12:40  gul
 
7
 * Binkd is under CVS again
 
8
 *
 
9
 *
 
10
 */
 
11
#include <stdio.h>
 
12
#include <errno.h>
 
13
#include <string.h>
 
14
#include <fcntl.h>
 
15
#ifdef HAVE_UNISTD_H
 
16
#include <unistd.h>
 
17
#endif
 
18
 
 
19
extern void Log (int lev, char *s,...);
 
20
 
 
21
int o_rename (const char *from, const char *to)
 
22
{
 
23
  int h, saved_errno;
 
24
 
 
25
  if ((h = open (to, O_CREAT | O_EXCL, 0666)) == -1)
 
26
    return -1;
 
27
  close (h);
 
28
  if (rename (from, to) == -1)
 
29
  {
 
30
    saved_errno = errno;
 
31
    unlink (to);
 
32
    errno = saved_errno;
 
33
    return -1;
 
34
  }
 
35
  return 0;
 
36
}