| 165 | } |
| 166 | |
| 167 | bool mime::parse(const char* file_path) { |
| 168 | ifstream fp; |
| 169 | |
| 170 | if (!fp.open_read(file_path)) { |
| 171 | logger_error("open %s error %s", file_path, last_serror()); |
| 172 | return false; |
| 173 | } |
| 174 | |
| 175 | string buf(1024); |
| 176 | const char* ptr; |
| 177 | int ret; |
| 178 | |
| 179 | while (1) { |
| 180 | #if 0 |
| 181 | if (fp.gets(buf, false) == false) |
| 182 | break; |
| 183 | ptr = buf.c_str(); |
| 184 | ret = (int) buf.length(); |
| 185 | #elif 1 |
| 186 | ret = fp.read(buf.c_str(), buf.capacity() - 1, false); |
| 187 | if (ret <= 0) { |
| 188 | break; |
| 189 | } |
| 190 | ptr = buf.c_str(); |
| 191 | #else |
| 192 | char ch; |
| 193 | if (!fp.read(ch)) { |
| 194 | break; |
| 195 | } |
| 196 | buf = (char) ch; |
| 197 | ptr = buf.c_str(); |
| 198 | ret = (int) buf.length(); |
| 199 | #endif |
| 200 | |
| 201 | if (mime_state_update(m_pMimeState, ptr, ret) == 1) { |
| 202 | break; |
| 203 | } |
| 204 | buf.clear(); |
| 205 | } |
| 206 | |
| 207 | fp.close(); |
| 208 | primary_head_finish(); |
| 209 | if (m_pFilePath) { |
| 210 | acl_myfree(m_pFilePath); |
| 211 | } |
| 212 | m_pFilePath = acl_mystrdup(file_path); |
| 213 | return true; |
| 214 | } |
| 215 | |
| 216 | static bool save_as(ifstream& in, ostream& out, long long pos, ssize_t len) { |
| 217 | if (pos < 0 || len <= 0) { |
no test coverage detected