Remove ifdef about memrchr() on MacOS

MacOS doesn't have memrchr() so there was an ifdef with a custom
implementation for it. Get rid of the ifdef by always using the custom
implementation.
This commit is contained in:
Lassi Kortela 2019-08-10 00:02:14 +03:00
parent daaa5aaed0
commit 95a1c1032c
1 changed files with 3 additions and 9 deletions

12
c/ios.c
View File

@ -29,10 +29,7 @@
#define MOST_OF(x) ((x) - ((x) >> 4)) #define MOST_OF(x) ((x) - ((x) >> 4))
/* OS-level primitive wrappers */ static void *our_memrchr(const void *s, int c, size_t n)
#if defined(MACOSX)
void *memrchr(const void *s, int c, size_t n)
{ {
const unsigned char *src = s + n; const unsigned char *src = s + n;
unsigned char uc = c; unsigned char uc = c;
@ -41,9 +38,6 @@ void *memrchr(const void *s, int c, size_t n)
return (void *)src; return (void *)src;
return NULL; return NULL;
} }
#else
extern void *memrchr(const void *s, int c, size_t n);
#endif
#if 0 #if 0
// poll for read, unless forwrite!=0 // poll for read, unless forwrite!=0
@ -362,7 +356,7 @@ size_t ios_write(struct ios *s, char *data, size_t n)
} else if (n <= space) { } else if (n <= space) {
if (s->bm == bm_line) { if (s->bm == bm_line) {
char *nl; char *nl;
if ((nl = (char *)memrchr(data, '\n', n)) != NULL) { if ((nl = (char *)our_memrchr(data, '\n', n)) != NULL) {
size_t linesz = nl - data + 1; size_t linesz = nl - data + 1;
s->bm = bm_block; s->bm = bm_block;
wrote += ios_write(s, data, linesz); wrote += ios_write(s, data, linesz);
@ -974,7 +968,7 @@ int ios_vprintf(struct ios *s, const char *format, va_list args)
s->bpos += (size_t)c; s->bpos += (size_t)c;
_write_update_pos(s); _write_update_pos(s);
// TODO: only works right if newline is at end // TODO: only works right if newline is at end
if (s->bm == bm_line && memrchr(start, '\n', (size_t)c)) if (s->bm == bm_line && our_memrchr(start, '\n', (size_t)c))
ios_flush(s); ios_flush(s);
va_end(al); va_end(al);
return c; return c;