Removes mp_puts/mp_fputs and adds mp_fwrite. In fact I wanted fwrite instead of puts, no need to make it more awkward with the implicit new lines.
Unified · Split
| @@ -309,18 +309,26 @@ static inline HANDLE get_handle(FILE *stream) · 308 unmodified lines | |||
| 309 | return wstream; | 309 | return wstream; |
| 310 | } | 310 | } |
| 311 | 311 | ||
| 312 | int mp_fputs(const char *str, FILE *stream) | 312 | size_t mp_fwrite(const void *restrict buffer, size_t size, size_t count, |
| 313 | FILE *restrict stream) | ||
| 313 | { | 314 | { |
| 314 | HANDLE wstream = get_handle(stream); | 315 | if (!size || !count) |
| 315 | if (mp_check_console(wstream)) | 316 | return 0; |
| 316 | return mp_console_fputs(wstream, bstr0(str)); | ||
| 317 | 317 | ||
| 318 | return fputs(str, stream); | 318 | HANDLE wstream = get_handle(stream); |
| 319 | } | 319 | if (mp_check_console(wstream)) { |
| 320 | unsigned char *start = (unsigned char *)buffer; | ||
| 321 | size_t c = 0; | ||
| 322 | for (; c < count; ++c) { | ||
| 323 | if (mp_console_write(wstream, (bstr){start, size}) <= 0) | ||
| 324 | break; | ||
| 325 | start += size; | ||
| 326 | } | ||
| 327 | return c; | ||
| 328 | } | ||
| 320 | 329 | ||
| 321 | int mp_puts(const char *str) | 330 | #undef fwrite |
| 322 | { | 331 | return fwrite(buffer, size, count, stream); |
| 323 | return mp_fputs(str, stdout); | ||
| 324 | } | 332 | } |
| 325 | 333 | ||
| 326 | #if HAVE_UWP | 334 | #if HAVE_UWP |
| @@ -106,8 +106,8 @@ char *mp_to_utf8(void *talloc_ctx, const wchar_t *s); · 105 unmodified lines | |||
| 106 | #include <sys/stat.h> | 106 | #include <sys/stat.h> |
| 107 | #include <fcntl.h> | 107 | #include <fcntl.h> |
| 108 | 108 | ||
| 109 | int mp_puts(const char *str); | 109 | size_t mp_fwrite(const void *restrict buffer, size_t size, size_t count, |
| 110 | int mp_fputs(const char *str, FILE *stream); | 110 | FILE *restrict stream); |
| 111 | int mp_printf(const char *format, ...) PRINTF_ATTRIBUTE(1, 2); | 111 | int mp_printf(const char *format, ...) PRINTF_ATTRIBUTE(1, 2); |
| 112 | int mp_fprintf(FILE *stream, const char *format, ...) PRINTF_ATTRIBUTE(2, 3); | 112 | int mp_fprintf(FILE *stream, const char *format, ...) PRINTF_ATTRIBUTE(2, 3); |
| 113 | int mp_open(const char *filename, int oflag, ...); | 113 | int mp_open(const char *filename, int oflag, ...); |
| @@ -176,8 +176,7 @@ int mp_glob(const char *restrict pattern, int flags, · 62 unmodified lines | |||
| 176 | int (*errfunc)(const char*, int), mp_glob_t *restrict pglob); | 176 | int (*errfunc)(const char*, int), mp_glob_t *restrict pglob); |
| 177 | void mp_globfree(mp_glob_t *pglob); | 177 | void mp_globfree(mp_glob_t *pglob); |
| 178 | 178 | ||
| 179 | #define puts(...) mp_puts(__VA_ARGS__) | 179 | #define fwrite(...) mp_fwrite(__VA_ARGS__) |
| 180 | #define fputs(...) mp_fputs(__VA_ARGS__) | ||
| 181 | #define printf(...) mp_printf(__VA_ARGS__) | 180 | #define printf(...) mp_printf(__VA_ARGS__) |
| 182 | #define fprintf(...) mp_fprintf(__VA_ARGS__) | 181 | #define fprintf(...) mp_fprintf(__VA_ARGS__) |
| 183 | #define open(...) mp_open(__VA_ARGS__) | 182 | #define open(...) mp_open(__VA_ARGS__) |
| @@ -32,7 +32,7 @@ int mp_console_vfprintf(void *wstream, const char *format, va_list args) · 31 unmodified lines | |||
| 32 | return 0; | 32 | return 0; |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | int mp_console_fputs(void *wstream, bstr str) | 35 | int mp_console_write(void *wstream, bstr str) |
| 36 | { | 36 | { |
| 37 | return 0; | 37 | return 0; |
| 38 | } | 38 | } |
| @@ -239,7 +239,7 @@ int mp_console_vfprintf(HANDLE wstream, const char *format, va_list args) · 238 unmodified lines | |||
| 239 | buffers->write_console_buf.len = 0; | 239 | buffers->write_console_buf.len = 0; |
| 240 | bstr_xappend_vasprintf(buffers, &buffers->write_console_buf, format, args); | 240 | bstr_xappend_vasprintf(buffers, &buffers->write_console_buf, format, args); |
| 241 | 241 | ||
| 242 | int ret = mp_console_fputs(wstream, buffers->write_console_buf); | 242 | int ret = mp_console_write(wstream, buffers->write_console_buf); |
| 243 | 243 | ||
| 244 | if (free_buf) | 244 | if (free_buf) |
| 245 | talloc_free(buffers); | 245 | talloc_free(buffers); |
| @@ -247,7 +247,7 @@ int mp_console_vfprintf(HANDLE wstream, const char *format, va_list args) · 1 unmodified line | |||
| 247 | return ret; | 247 | return ret; |
| 248 | } | 248 | } |
| 249 | 249 | ||
| 250 | int mp_console_fputs(HANDLE wstream, bstr str) | 250 | int mp_console_write(HANDLE wstream, bstr str) |
| 251 | { | 251 | { |
| 252 | struct tmp_buffers *buffers = FlsGetValue(tmp_buffers_key); | 252 | struct tmp_buffers *buffers = FlsGetValue(tmp_buffers_key); |
| 253 | bool free_buf = false; | 253 | bool free_buf = false; |
| @@ -57,7 +57,7 @@ void terminal_get_size2(int *rows, int *cols, int *px_width, int *px_height); · 56 unmodified lines | |||
| 57 | 57 | ||
| 58 | // Windows only. | 58 | // Windows only. |
| 59 | int mp_console_vfprintf(void *wstream, const char *format, va_list args); | 59 | int mp_console_vfprintf(void *wstream, const char *format, va_list args); |
| 60 | int mp_console_fputs(void *wstream, bstr str); | 60 | int mp_console_write(void *wstream, bstr str); |
| 61 | bool mp_check_console(void *handle); | 61 | bool mp_check_console(void *handle); |
| 62 | 62 | ||
| 63 | /* Windows-only function to attach to the parent process's console */ | 63 | /* Windows-only function to attach to the parent process's console */ |
| @@ -114,7 +114,7 @@ int mp_msg_find_level(const char *s) {return 0;}; · 113 unmodified lines | |||
| 114 | int mp_msg_level(struct mp_log *log) {return 0;}; | 114 | int mp_msg_level(struct mp_log *log) {return 0;}; |
| 115 | void mp_msg_set_max_level(struct mp_log *log, int lev) {}; | 115 | void mp_msg_set_max_level(struct mp_log *log, int lev) {}; |
| 116 | int mp_console_vfprintf(void *wstream, const char *format, va_list args) {return 0;}; | 116 | int mp_console_vfprintf(void *wstream, const char *format, va_list args) {return 0;}; |
| 117 | int mp_console_fputs(void *wstream, bstr str) {return 0;}; | 117 | int mp_console_write(void *wstream, bstr str) {return 0;}; |
| 118 | bool mp_check_console(void *handle) { return false; }; | 118 | bool mp_check_console(void *handle) { return false; }; |
| 119 | void mp_set_avdict(AVDictionary **dict, char **kv) {}; | 119 | void mp_set_avdict(AVDictionary **dict, char **kv) {}; |
| 120 | struct mp_log *mp_log_new(void *talloc_ctx, struct mp_log *parent, | 120 | struct mp_log *mp_log_new(void *talloc_ctx, struct mp_log *parent, |