History

win32: change fputs to fwrite wrapper

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.

Kacper Michajłow committed 2 years ago

Commit c389f9e1 parent 6177aa76 files · +25 −18Browse files

Unified · Split

6 files
  1. osdep/io.c +17 −9
  2. osdep/io.h +3 −4
  3. osdep/terminal-dummy.c +1 −1
  4. osdep/terminal-win.c +2 −2
  5. osdep/terminal.h +1 −1
  6. test/test_utils.c +1 −1
osdep/io.c+17−9
@@ -309,18 +309,26 @@ static inline HANDLE get_handle(FILE *stream) · 308 unmodified lines
309 return wstream;309 return wstream;
310}310}
311 311
312int mp_fputs(const char *str, FILE *stream)312size_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
321int 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_UWP334#if HAVE_UWP
osdep/io.h+3−4
@@ -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
109int mp_puts(const char *str);109size_t mp_fwrite(const void *restrict buffer, size_t size, size_t count,
110int mp_fputs(const char *str, FILE *stream);110 FILE *restrict stream);
111int mp_printf(const char *format, ...) PRINTF_ATTRIBUTE(1, 2);111int mp_printf(const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
112int mp_fprintf(FILE *stream, const char *format, ...) PRINTF_ATTRIBUTE(2, 3);112int mp_fprintf(FILE *stream, const char *format, ...) PRINTF_ATTRIBUTE(2, 3);
113int mp_open(const char *filename, int oflag, ...);113int 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);
177void mp_globfree(mp_glob_t *pglob);177void 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__)
osdep/terminal-dummy.c+1−1
@@ -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
35int mp_console_fputs(void *wstream, bstr str)35int mp_console_write(void *wstream, bstr str)
36{36{
37 return 0;37 return 0;
38}38}
osdep/terminal-win.c+2−2
@@ -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
250int mp_console_fputs(HANDLE wstream, bstr str)250int 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;
osdep/terminal.h+1−1
@@ -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.
59int mp_console_vfprintf(void *wstream, const char *format, va_list args);59int mp_console_vfprintf(void *wstream, const char *format, va_list args);
60int mp_console_fputs(void *wstream, bstr str);60int mp_console_write(void *wstream, bstr str);
61bool mp_check_console(void *handle);61bool 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 */
test/test_utils.c+1−1
@@ -114,7 +114,7 @@ int mp_msg_find_level(const char *s) {return 0;}; · 113 unmodified lines
114int mp_msg_level(struct mp_log *log) {return 0;};114int mp_msg_level(struct mp_log *log) {return 0;};
115void mp_msg_set_max_level(struct mp_log *log, int lev) {};115void mp_msg_set_max_level(struct mp_log *log, int lev) {};
116int mp_console_vfprintf(void *wstream, const char *format, va_list args) {return 0;};116int mp_console_vfprintf(void *wstream, const char *format, va_list args) {return 0;};
117int mp_console_fputs(void *wstream, bstr str) {return 0;};117int mp_console_write(void *wstream, bstr str) {return 0;};
118bool mp_check_console(void *handle) { return false; };118bool mp_check_console(void *handle) { return false; };
119void mp_set_avdict(AVDictionary **dict, char **kv) {};119void mp_set_avdict(AVDictionary **dict, char **kv) {};
120struct mp_log *mp_log_new(void *talloc_ctx, struct mp_log *parent,120struct mp_log *mp_log_new(void *talloc_ctx, struct mp_log *parent,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t