SameBoy | Accurate GB/GBC emulator |
| download: https://git.y1.nz/archives/sameboy.tar.gz | |
| README | Files | Log | Refs | LICENSE |
Windows/stdio.c
1 #include <stdio.h>
2 #include <unistd.h>
3
4 #ifdef USE_MSVCRT_DLL
5
6 FILE *__acrt_iob_func(unsigned index)
7 {
8 static FILE *files[3];
9 if (index > sizeof(files) / sizeof(files[0])) return NULL;
10 if (files[index]) return files[index];
11 return (files[index] = fdopen(index, index == STDIN_FILENO? "r" : "w"));
12 }
13
14 #endif
15
16 #ifndef __MINGW32__
17 #ifndef __LIBRETRO__
18 int vasprintf(char **str, const char *fmt, va_list args)
19 {
20 size_t size = _vscprintf(fmt, args) + 1;
21 *str = (char*)malloc(size);
22 int ret = vsprintf(*str, fmt, args);
23 if (ret != size - 1) {
24 free(*str);
25 *str = NULL;
26 return -1;
27 }
28 return ret;
29 }
30
31 int asprintf(char **strp, const char *fmt, ...)
32 {
33 va_list args;
34 va_start(args, fmt);
35 int r = vasprintf(strp, fmt, args);
36 va_end(args);
37 return r;
38 }
39
40 #endif
41 #endif
42
43 /* This code is public domain -- Will Hartung 4/9/09 */
44 intptr_t getline(char **lineptr, size_t *n, FILE *stream)
45 {
46 char *bufptr = NULL;
47 char *p = bufptr;
48 size_t size;
49 int c;
50
51 if (lineptr == NULL) {
52 return -1;
53 }
54 if (stream == NULL) {
55 return -1;
56 }
57 if (n == NULL) {
58 return -1;
59 }
60 bufptr = *lineptr;
61 size = *n;
62
63 errno = 0;
64 c = fgetc(stream);
65 if (c == EOF) {
66 return -1;
67 }
68 if (bufptr == NULL) {
69 bufptr = (char*)malloc(128);
70 if (bufptr == NULL) {
71 return -1;
72 }
73 size = 128;
74 }
75 p = bufptr;
76 while (c != EOF) {
77 if ((p - bufptr) > (size - 1)) {
78 size = size + 128;
79 bufptr = (char*)realloc(bufptr, size);
80 if (bufptr == NULL) {
81 return -1;
82 }
83 }
84 *p++ = c;
85 if (c == '\n') {
86 break;
87 }
88 c = fgetc(stream);
89 }
90
91 *p++ = '\0';
92 *lineptr = bufptr;
93 *n = size;
94
95 return p - bufptr - 1;
96 }
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.