| 94 | } |
| 95 | |
| 96 | bool fstream::rename(const char* from_path, const char* to_path) |
| 97 | { |
| 98 | if (from_path == NULL || *from_path == 0) { |
| 99 | logger_error("from_path NULL"); |
| 100 | return false; |
| 101 | } |
| 102 | if (to_path == NULL || *to_path == 0) { |
| 103 | logger_error("to_path NULL"); |
| 104 | return false; |
| 105 | } |
| 106 | |
| 107 | bool need_reopen; |
| 108 | unsigned int oflags, omode; |
| 109 | |
| 110 | #if defined(_WIN32) || defined(_WIN64) |
| 111 | if (opened() && stream_ != NULL) { |
| 112 | oflags = stream_->oflags; |
| 113 | omode = stream_->omode; |
| 114 | // WINDOWS �±����ȹر��ļ���� |
| 115 | close(); |
| 116 | need_reopen = true; |
| 117 | } else { |
| 118 | oflags = 0; |
| 119 | omode = 0; |
| 120 | need_reopen = false; |
| 121 | } |
| 122 | #else |
| 123 | oflags = 0; |
| 124 | omode = 0; |
| 125 | need_reopen = false; |
| 126 | #endif |
| 127 | if (::rename(from_path, to_path) == -1) { |
| 128 | logger_error("rename from %s to %s error %s", |
| 129 | from_path, to_path, last_serror()); |
| 130 | return false; |
| 131 | } |
| 132 | |
| 133 | if (!need_reopen) { |
| 134 | return true; |
| 135 | } |
| 136 | |
| 137 | // ��� windows ƽ̨����Ҫ���´��ļ���� |
| 138 | return open(to_path, oflags, omode); |
| 139 | } |
| 140 | |
| 141 | const char* fstream::file_path() const |
| 142 | { |