Mercurial > hg > octave-lojdl > gnulib-hg
annotate lib/rename.c @ 4229:c7ddde35beec
Make this module usable in shared libraries.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Fri, 31 Jan 2003 15:47:03 +0000 |
parents | 8784488b0ea1 |
children | 092d9a2797a7 |
rev | line source |
---|---|
3102
a17f2d7d7ee1
Include stdlib.h, string.h or strings.h, and xalloc.h.
Jim Meyering <jim@meyering.net>
parents:
3099
diff
changeset
|
1 /* Work around the bug in some systems whereby rename fails when the source |
3782
8784488b0ea1
Mention that this wrapper is needed also on mips-dec-ultrix4.4 systems.
Jim Meyering <jim@meyering.net>
parents:
3244
diff
changeset
|
2 path has a trailing slash. The rename functions of SunOS 4.1.1_U1 and |
8784488b0ea1
Mention that this wrapper is needed also on mips-dec-ultrix4.4 systems.
Jim Meyering <jim@meyering.net>
parents:
3244
diff
changeset
|
3 mips-dec-ultrix4.4 have this bug. |
4229
c7ddde35beec
Make this module usable in shared libraries.
Bruno Haible <bruno@clisp.org>
parents:
3782
diff
changeset
|
4 Copyright (C) 2001-2003 Free Software Foundation, Inc. |
3099 | 5 |
6 This program is free software; you can redistribute it and/or modify | |
7 it under the terms of the GNU General Public License as published by | |
8 the Free Software Foundation; either version 2, or (at your option) | |
9 any later version. | |
10 | |
11 This program is distributed in the hope that it will be useful, | |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 GNU General Public License for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
17 along with this program; if not, write to the Free Software Foundation, | |
18 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |
19 | |
20 /* written by Volker Borchert */ | |
21 | |
4229
c7ddde35beec
Make this module usable in shared libraries.
Bruno Haible <bruno@clisp.org>
parents:
3782
diff
changeset
|
22 #if HAVE_CONFIG_H |
c7ddde35beec
Make this module usable in shared libraries.
Bruno Haible <bruno@clisp.org>
parents:
3782
diff
changeset
|
23 # include <config.h> |
c7ddde35beec
Make this module usable in shared libraries.
Bruno Haible <bruno@clisp.org>
parents:
3782
diff
changeset
|
24 #endif |
c7ddde35beec
Make this module usable in shared libraries.
Bruno Haible <bruno@clisp.org>
parents:
3782
diff
changeset
|
25 #undef rename |
c7ddde35beec
Make this module usable in shared libraries.
Bruno Haible <bruno@clisp.org>
parents:
3782
diff
changeset
|
26 |
3099 | 27 #include <stdio.h> |
3102
a17f2d7d7ee1
Include stdlib.h, string.h or strings.h, and xalloc.h.
Jim Meyering <jim@meyering.net>
parents:
3099
diff
changeset
|
28 #if HAVE_STDLIB_H |
a17f2d7d7ee1
Include stdlib.h, string.h or strings.h, and xalloc.h.
Jim Meyering <jim@meyering.net>
parents:
3099
diff
changeset
|
29 # include <stdlib.h> |
a17f2d7d7ee1
Include stdlib.h, string.h or strings.h, and xalloc.h.
Jim Meyering <jim@meyering.net>
parents:
3099
diff
changeset
|
30 #endif |
a17f2d7d7ee1
Include stdlib.h, string.h or strings.h, and xalloc.h.
Jim Meyering <jim@meyering.net>
parents:
3099
diff
changeset
|
31 |
a17f2d7d7ee1
Include stdlib.h, string.h or strings.h, and xalloc.h.
Jim Meyering <jim@meyering.net>
parents:
3099
diff
changeset
|
32 #if HAVE_STRING_H |
a17f2d7d7ee1
Include stdlib.h, string.h or strings.h, and xalloc.h.
Jim Meyering <jim@meyering.net>
parents:
3099
diff
changeset
|
33 # include <string.h> |
a17f2d7d7ee1
Include stdlib.h, string.h or strings.h, and xalloc.h.
Jim Meyering <jim@meyering.net>
parents:
3099
diff
changeset
|
34 #else |
a17f2d7d7ee1
Include stdlib.h, string.h or strings.h, and xalloc.h.
Jim Meyering <jim@meyering.net>
parents:
3099
diff
changeset
|
35 # include <strings.h> |
a17f2d7d7ee1
Include stdlib.h, string.h or strings.h, and xalloc.h.
Jim Meyering <jim@meyering.net>
parents:
3099
diff
changeset
|
36 #endif |
a17f2d7d7ee1
Include stdlib.h, string.h or strings.h, and xalloc.h.
Jim Meyering <jim@meyering.net>
parents:
3099
diff
changeset
|
37 |
3244
5a129aed765a
Use "", not <> to include non-system header files.
Jim Meyering <jim@meyering.net>
parents:
3237
diff
changeset
|
38 #include "dirname.h" |
5a129aed765a
Use "", not <> to include non-system header files.
Jim Meyering <jim@meyering.net>
parents:
3237
diff
changeset
|
39 #include "xalloc.h" |
3099 | 40 |
41 #ifndef HAVE_DECL_FREE | |
42 "this configure-time declaration test was not run" | |
43 #endif | |
44 #if !HAVE_DECL_FREE | |
45 void free (); | |
46 #endif | |
47 | |
3102
a17f2d7d7ee1
Include stdlib.h, string.h or strings.h, and xalloc.h.
Jim Meyering <jim@meyering.net>
parents:
3099
diff
changeset
|
48 /* Rename the file SRC_PATH to DST_PATH, removing any trailing |
a17f2d7d7ee1
Include stdlib.h, string.h or strings.h, and xalloc.h.
Jim Meyering <jim@meyering.net>
parents:
3099
diff
changeset
|
49 slashes from SRC_PATH. Needed for SunOS 4.1.1_U1. */ |
3099 | 50 |
51 int | |
52 rpl_rename (const char *src_path, const char *dst_path) | |
53 { | |
54 char *src_temp; | |
3102
a17f2d7d7ee1
Include stdlib.h, string.h or strings.h, and xalloc.h.
Jim Meyering <jim@meyering.net>
parents:
3099
diff
changeset
|
55 int ret_val; |
a17f2d7d7ee1
Include stdlib.h, string.h or strings.h, and xalloc.h.
Jim Meyering <jim@meyering.net>
parents:
3099
diff
changeset
|
56 size_t s_len = strlen (src_path); |
3099 | 57 |
3102
a17f2d7d7ee1
Include stdlib.h, string.h or strings.h, and xalloc.h.
Jim Meyering <jim@meyering.net>
parents:
3099
diff
changeset
|
58 if (s_len && src_path[s_len - 1] == '/') |
3099 | 59 { |
60 src_temp = xstrdup (src_path); | |
3102
a17f2d7d7ee1
Include stdlib.h, string.h or strings.h, and xalloc.h.
Jim Meyering <jim@meyering.net>
parents:
3099
diff
changeset
|
61 strip_trailing_slashes (src_temp); |
3099 | 62 } |
63 else | |
64 src_temp = (char *) src_path; | |
65 | |
3102
a17f2d7d7ee1
Include stdlib.h, string.h or strings.h, and xalloc.h.
Jim Meyering <jim@meyering.net>
parents:
3099
diff
changeset
|
66 ret_val = rename (src_temp, dst_path); |
3099 | 67 |
68 if (src_temp != src_path) | |
69 free (src_temp); | |
70 | |
3102
a17f2d7d7ee1
Include stdlib.h, string.h or strings.h, and xalloc.h.
Jim Meyering <jim@meyering.net>
parents:
3099
diff
changeset
|
71 return ret_val; |
3099 | 72 } |