| 239 | } |
| 240 | |
| 241 | char *Process::read(u32 *num_bytes_read, char *data, u32 len) |
| 242 | { |
| 243 | CE_ENSURE(process_internal::is_open(_priv) == true); |
| 244 | #if CROWN_PLATFORM_WINDOWS |
| 245 | DWORD read; |
| 246 | BOOL success = FALSE; |
| 247 | |
| 248 | success = ReadFile(_priv->stdout_rd, data, len, &read, NULL); |
| 249 | if (!success) { |
| 250 | *num_bytes_read = UINT32_MAX; |
| 251 | return NULL; |
| 252 | } |
| 253 | |
| 254 | if (read == 0) { |
| 255 | // EOF |
| 256 | *num_bytes_read = 0; |
| 257 | return NULL; |
| 258 | } else { |
| 259 | *num_bytes_read = read; |
| 260 | return data; |
| 261 | } |
| 262 | #else |
| 263 | CE_ENSURE(_priv->file != NULL); |
| 264 | size_t read = fread(data, 1, len, _priv->file); |
| 265 | if (read != len) { |
| 266 | if (feof(_priv->file) != 0) { |
| 267 | if (read == 0) { |
| 268 | *num_bytes_read = 0; |
| 269 | return NULL; |
| 270 | } |
| 271 | } else if (ferror(_priv->file) != 0) { |
| 272 | *num_bytes_read = UINT32_MAX; |
| 273 | return NULL; |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | *num_bytes_read = read; |
| 278 | return data; |
| 279 | #endif // if CROWN_PLATFORM_WINDOWS |
| 280 | } |
| 281 | |
| 282 | } // namespace crown |