Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Tor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
The Tor Project
Core
Tor
Commits
6453a255
Commit
6453a255
authored
20 years ago
by
Nick Mathewson
Browse files
Options
Downloads
Patches
Plain Diff
Add replace_file to util.[ch] to survive stupidity of windows rename call
svn:r2208
parent
98b8a89a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/common/util.c
+27
-0
27 additions, 0 deletions
src/common/util.c
src/common/util.h
+1
-0
1 addition, 0 deletions
src/common/util.h
with
28 additions
and
0 deletions
src/common/util.c
+
27
−
0
View file @
6453a255
...
...
@@ -1559,6 +1559,33 @@ char *expand_filename(const char *filename)
}
}
/**
* Rename the file 'from' to the file 'to'. On unix, this is the same as
* rename(2). On windows, this removes 'to' first if it already exists.
* Returns 0 on success. Returns -1 and sets errno on failure.
*/
int
replace_file
(
const
char
*
from
,
const
char
*
to
)
{
#ifndef MS_WINDOWS
return
rename
(
from
,
to
);
#else
switch
(
file_status
(
to
))
{
case
FN_NOENT
:
break
;
case
FN_FILE
:
if
(
unlink
(
to
))
return
-
1
;
break
;
case
FN_ERROR
:
return
-
1
;
case
FN_DIR
:
errno
=
EISDIR
;
return
-
1
;
}
return
rename
(
from
,
to
);
#endif
}
/** Return true iff <b>ip</b> (in host order) is an IP reserved to localhost,
* or reserved for local networks by RFC 1918.
*/
...
...
This diff is collapsed.
Click to expand it.
src/common/util.h
+
1
−
0
View file @
6453a255
...
...
@@ -220,6 +220,7 @@ int write_str_to_file(const char *fname, const char *str);
char
*
read_file_to_str
(
const
char
*
filename
);
int
parse_line_from_file
(
char
*
line
,
int
maxlen
,
FILE
*
f
,
char
**
key_out
,
char
**
value_out
);
char
*
expand_filename
(
const
char
*
filename
);
int
replace_file
(
const
char
*
from
,
const
char
*
to
);
int
spawn_func
(
int
(
*
func
)(
void
*
),
void
*
data
);
void
spawn_exit
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment