* Implement a different way to delete a password from the cache.
[alpine.git] / pith / osdep / rename.c
blob1e7715909f0a648e9e378a295df3a04bb0921d47
1 /*
2 * ========================================================================
3 * Copyright 2013-2022 Eduardo Chappa
4 * Copyright 2006 University of Washington
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * ========================================================================
15 #include <system.h>
16 #include "err_desc.h"
17 #include "../charconv/utf8.h"
18 #include "../charconv/filesys.h"
19 #include "rename.h"
22 /*----------------------------------------------------------------------
23 Rename a file
25 Args: tmpfname -- Old name of file
26 fname -- New name of file
28 Result: File is renamed. Returns 0 on success, else -1 on error
29 and errno is valid.
30 ----*/
31 int
32 rename_file(char *tmpfname, char *fname)
34 #if HAVE_RENAME
35 return(our_rename(tmpfname, fname));
36 #else
37 # if defined(_WINDOWS)
38 int ret;
41 * DOS rename doesn't unlink destination for us...
43 if((ret = our_unlink(fname)) && (errno == EPERM)){
44 ret = -5;
46 else{
47 ret = our_rename(tmpfname, fname);
48 if(ret)
49 ret = -1;
52 return(ret);
53 # else
54 int status;
56 our_unlink(fname);
57 if ((status = link(tmpfname, fname)) != 0)
58 return(status);
60 our_unlink(tmpfname);
61 return(0);
62 # endif
63 #endif