-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add basic win support #67
base: master
Are you sure you want to change the base?
Changes from 1 commit
7c01e0b
67a4075
55f7773
16fcfcf
308d127
cc6fb5d
bf81e2b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -159,7 +159,7 @@ static int fy_tag_token_format_internal(const struct fy_token *fyt, void *out, s | |
if (out) { | ||
outsz = *outszp; | ||
o = out; | ||
oe = out + outsz; | ||
oe = (char *)out + outsz; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I get this why it needs to happen but I still dislike MSVC here. |
||
} | ||
|
||
if (!fyt->tag.fyt_td) | ||
|
@@ -246,7 +246,7 @@ static int fy_tag_directive_token_format_internal(const struct fy_token *fyt, | |
if (out) { | ||
outsz = *outszp; | ||
o = out; | ||
oe = out + outsz; | ||
oe = (char *)out + outsz; | ||
} | ||
|
||
#define O_CPY(_src, _len) \ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,16 +15,101 @@ | |
#include <stdlib.h> | ||
#include <string.h> | ||
#include <errno.h> | ||
#if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__)) | ||
#include <termios.h> | ||
#include <unistd.h> | ||
#include <sys/select.h> | ||
#include <sys/time.h> | ||
#include <sys/types.h> | ||
#elif defined(_MSC_VER) | ||
#include <windows.h> | ||
#endif | ||
|
||
#include "fy-utf8.h" | ||
#include "fy-ctype.h" | ||
#include "fy-utils.h" | ||
|
||
int fy_get_pagesize() { | ||
#if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__)) | ||
return sysconf(_SC_PAGESIZE); | ||
#elif defined (_MSC_VER) | ||
SYSTEM_INFO si; | ||
GetSystemInfo(&si); | ||
return si.dwPageSize; | ||
#endif | ||
} | ||
|
||
#if defined(_MSC_VER) | ||
#ifndef VA_COPY | ||
# ifdef HAVE_VA_COPY | ||
# define VA_COPY(dest, src) va_copy(dest, src) | ||
# else | ||
# ifdef HAVE___VA_COPY | ||
# define VA_COPY(dest, src) __va_copy(dest, src) | ||
# else | ||
# define VA_COPY(dest, src) (dest) = (src) | ||
# endif | ||
# endif | ||
#endif | ||
|
||
#define INIT_SZ 128 | ||
|
||
int | ||
vasprintf(char **str, const char *fmt, va_list ap) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe you're over doing it here. IIRC vsnprintf with a NULL string returns the exact size, so you can just call it twice, first call to find the size, second call after allocating it. |
||
{ | ||
int ret; | ||
va_list ap2; | ||
char *string, *newstr; | ||
size_t len; | ||
|
||
if ((string = malloc(INIT_SZ)) == NULL) | ||
goto fail; | ||
|
||
VA_COPY(ap2, ap); | ||
ret = vsnprintf(string, INIT_SZ, fmt, ap2); | ||
va_end(ap2); | ||
if (ret >= 0 && ret < INIT_SZ) { /* succeeded with initial alloc */ | ||
*str = string; | ||
} else if (ret == INT_MAX || ret < 0) { /* Bad length */ | ||
free(string); | ||
goto fail; | ||
} else { /* bigger than initial, realloc allowing for nul */ | ||
len = (size_t)ret + 1; | ||
if ((newstr = realloc(string, len)) == NULL) { | ||
free(string); | ||
goto fail; | ||
} | ||
VA_COPY(ap2, ap); | ||
ret = vsnprintf(newstr, len, fmt, ap2); | ||
va_end(ap2); | ||
if (ret < 0 || (size_t)ret >= len) { /* failed with realloc'ed string */ | ||
free(newstr); | ||
goto fail; | ||
} | ||
*str = newstr; | ||
} | ||
return (ret); | ||
|
||
fail: | ||
*str = NULL; | ||
errno = ENOMEM; | ||
return (-1); | ||
} | ||
|
||
int asprintf(char **str, const char *fmt, ...) | ||
{ | ||
va_list ap; | ||
int ret; | ||
|
||
*str = NULL; | ||
va_start(ap, fmt); | ||
ret = vasprintf(str, fmt, ap); | ||
va_end(ap); | ||
|
||
return ret; | ||
} | ||
#endif | ||
|
||
#if defined(__APPLE__) && (_POSIX_C_SOURCE < 200809L) | ||
|
||
/* | ||
|
@@ -397,6 +482,7 @@ int fy_tag_scan(const char *data, size_t len, struct fy_tag_scan_info *info) | |
return 0; | ||
} | ||
|
||
#if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__)) | ||
/* simple terminal methods; mainly for getting size of terminal */ | ||
int fy_term_set_raw(int fd, struct termios *oldt) | ||
{ | ||
|
@@ -632,3 +718,4 @@ int fy_term_query_size(int fd, int *rows, int *cols) | |
|
||
return ret; | ||
} | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably group all these together