Mercurial > hg > octave-kai > gnulib-hg
annotate lib/rename.c @ 10780:5c7a68d31801
Add support for Haiku.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Mon, 10 Nov 2008 12:37:32 +0100 |
parents | bbbbbf4cd1c5 |
children | df9a59a3f8bc |
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 |
5907 | 2 file has a trailing slash. The rename functions of SunOS 4.1.1_U1 and |
3782
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. |
7302
8a1a9361108c
* _fpending.c: Include <config.h> unconditionally, since we no
Paul Eggert <eggert@cs.ucla.edu>
parents:
6259
diff
changeset
|
4 |
8a1a9361108c
* _fpending.c: Include <config.h> unconditionally, since we no
Paul Eggert <eggert@cs.ucla.edu>
parents:
6259
diff
changeset
|
5 Copyright (C) 2001, 2002, 2003, 2005, 2006 Free Software Foundation, Inc. |
3099 | 6 |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
7302
diff
changeset
|
7 This program is free software: you can redistribute it and/or modify |
3099 | 8 it under the terms of the GNU General Public License as published by |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
7302
diff
changeset
|
9 the Free Software Foundation; either version 3 of the License, or |
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
7302
diff
changeset
|
10 (at your option) any later version. |
3099 | 11 |
12 This program is distributed in the hope that it will be useful, | |
13 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 GNU General Public License for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
7302
diff
changeset
|
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
3099 | 19 |
20 /* written by Volker Borchert */ | |
21 | |
7302
8a1a9361108c
* _fpending.c: Include <config.h> unconditionally, since we no
Paul Eggert <eggert@cs.ucla.edu>
parents:
6259
diff
changeset
|
22 #include <config.h> |
4229
c7ddde35beec
Make this module usable in shared libraries.
Bruno Haible <bruno@clisp.org>
parents:
3782
diff
changeset
|
23 #undef rename |
c7ddde35beec
Make this module usable in shared libraries.
Bruno Haible <bruno@clisp.org>
parents:
3782
diff
changeset
|
24 |
3099 | 25 #include <stdio.h> |
4674 | 26 #include <stdlib.h> |
27 #include <string.h> | |
3102
a17f2d7d7ee1
Include stdlib.h, string.h or strings.h, and xalloc.h.
Jim Meyering <jim@meyering.net>
parents:
3099
diff
changeset
|
28 |
3244
5a129aed765a
Use "", not <> to include non-system header files.
Jim Meyering <jim@meyering.net>
parents:
3237
diff
changeset
|
29 #include "dirname.h" |
5a129aed765a
Use "", not <> to include non-system header files.
Jim Meyering <jim@meyering.net>
parents:
3237
diff
changeset
|
30 #include "xalloc.h" |
3099 | 31 |
5907 | 32 /* Rename the file SRC to DST, removing any trailing |
33 slashes from SRC. Needed for SunOS 4.1.1_U1. */ | |
3099 | 34 |
35 int | |
5907 | 36 rpl_rename (char const *src, char const *dst) |
3099 | 37 { |
38 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
|
39 int ret_val; |
5907 | 40 size_t s_len = strlen (src); |
3099 | 41 |
5907 | 42 if (s_len && src[s_len - 1] == '/') |
3099 | 43 { |
5907 | 44 src_temp = xstrdup (src); |
3102
a17f2d7d7ee1
Include stdlib.h, string.h or strings.h, and xalloc.h.
Jim Meyering <jim@meyering.net>
parents:
3099
diff
changeset
|
45 strip_trailing_slashes (src_temp); |
3099 | 46 } |
47 else | |
5907 | 48 src_temp = (char *) src; |
3099 | 49 |
5907 | 50 ret_val = rename (src_temp, dst); |
3099 | 51 |
5907 | 52 if (src_temp != src) |
3099 | 53 free (src_temp); |
54 | |
3102
a17f2d7d7ee1
Include stdlib.h, string.h or strings.h, and xalloc.h.
Jim Meyering <jim@meyering.net>
parents:
3099
diff
changeset
|
55 return ret_val; |
3099 | 56 } |