Rev 5220 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5220 | Rev 6536 | ||
---|---|---|---|
1 | /* _rename.c -- Implementation of the low-level rename() routine |
1 | /* _rename.c -- Implementation of the low-level rename() routine |
2 | * |
2 | * |
3 | * Copyright (c) 2004 National Semiconductor Corporation |
3 | * Copyright (c) 2004 National Semiconductor Corporation |
4 | * |
4 | * |
5 | * The authors hereby grant permission to use, copy, modify, distribute, |
5 | * The authors hereby grant permission to use, copy, modify, distribute, |
6 | * and license this software and its documentation for any purpose, provided |
6 | * and license this software and its documentation for any purpose, provided |
7 | * that existing copyright notices are retained in all copies and that this |
7 | * that existing copyright notices are retained in all copies and that this |
8 | * notice is included verbatim in any distributions. No written agreement, |
8 | * notice is included verbatim in any distributions. No written agreement, |
9 | * license, or royalty fee is required for any of the authorized uses. |
9 | * license, or royalty fee is required for any of the authorized uses. |
10 | * Modifications to this software may be copyrighted by their authors |
10 | * Modifications to this software may be copyrighted by their authors |
11 | * and need not follow the licensing terms described here, provided that |
11 | * and need not follow the licensing terms described here, provided that |
12 | * the new terms are clearly indicated on the first page of each file where |
12 | * the new terms are clearly indicated on the first page of each file where |
13 | * they apply. |
13 | * they apply. |
14 | */ |
14 | */ |
15 | 15 | ||
16 | #include |
16 | #include |
17 | #include |
- | |
18 | #include |
17 | #include |
- | 18 | #include |
|
19 | #include |
19 | #include |
- | 20 | #include |
|
20 | 21 | ||
21 | int _rename (char *from, char *to) |
22 | int _rename (char *from, char *to) |
22 | { |
23 | { |
23 | void* buf; |
24 | void* buf; |
24 | int f_from; |
25 | int f_from; |
25 | int f_to; |
26 | int f_to; |
26 | int size; |
27 | int size; |
27 | 28 | ||
28 | f_from = open(from,O_RDONLY); |
29 | f_from = open(from,O_RDONLY); |
29 | 30 | ||
30 | if (f_from < 0) |
31 | if (f_from < 0) |
31 | { |
32 | { |
32 | errno = ENOENT; |
33 | errno = ENOENT; |
33 | return -1; |
34 | return -1; |
34 | }; |
35 | }; |
35 | 36 | ||
36 | f_to = open(to,O_CREAT|O_WRONLY|O_EXCL); |
37 | f_to = open(to,O_CREAT|O_WRONLY|O_EXCL); |
37 | 38 | ||
38 | if (f_to < 0) |
39 | if (f_to < 0) |
39 | { |
40 | { |
40 | close(f_from); |
41 | close(f_from); |
41 | errno = EACCES; |
42 | errno = EACCES; |
42 | return -1; |
43 | return -1; |
43 | }; |
44 | }; |
44 | 45 | ||
45 | buf = alloca(32768); |
46 | buf = alloca(32768); |
46 | 47 | ||
47 | do |
48 | do |
48 | { |
49 | { |
49 | size = read(f_from, buf, 32768); |
50 | size = read(f_from, buf, 32768); |
50 | 51 | ||
51 | if (size >= 0) |
52 | if (size >= 0) |
52 | size = write(f_to, buf, size); |
53 | size = write(f_to, buf, size); |
53 | 54 | ||
54 | }while (size == 32768); |
55 | }while (size == 32768); |
55 | 56 | ||
56 | close(f_to); |
57 | close(f_to); |
57 | close(f_from); |
58 | close(f_from); |
58 | 59 | ||
59 | if (size == -1) |
60 | if (size == -1) |
60 | { |
61 | { |
61 | errno = EACCES; |
62 | errno = EACCES; |
62 | return -1; |
63 | return -1; |
63 | }; |
64 | }; |
64 | 65 | ||
65 | remove(from); |
66 | remove(from); |
66 | 67 | ||
67 | return (0); |
68 | return (0); |
68 | };>> |
69 | };>> |