Skip to content
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

Header conflict #1

Open
apfeltee opened this issue May 7, 2020 · 0 comments
Open

Header conflict #1

apfeltee opened this issue May 7, 2020 · 0 comments

Comments

@apfeltee
Copy link

apfeltee commented May 7, 2020

In linenoise.cpp, in the #ifdefs for _WIN32, headers <string.h> (should be <cstring>) are not included, leading to undefined decls for strdup, etc.

So change the head of linenoise.cpp to:

/* gcc's C++17 mode hides most of signal.h */
#if defined(__GNUC__)
    #define _GNU_SOURCE
#endif
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <errno.h>
#include <fcntl.h>

#include <signal.h>
#include <sys/stat.h>
#include <sys/types.h>

#include <string>
#include <vector>
#include <unordered_map>
#include <memory>
#include <atomic>

#ifdef _WIN32
    #include <conio.h>
    #include <windows.h>
    #include <io.h>
// thanks @Technici4n [180385768a]
    #if defined(_MSC_VER) && _MSC_VER < 1900
        #define snprintf _snprintf// Microsoft headers use underscores in some names
    #endif
    #define isatty _isatty
    #define write _write
    #define STDIN_FILENO 0
#else /* _WIN32 */
    #include <termios.h>
    #include <unistd.h>
// thanks @theopolis commit [30d97e1d4] from [c894b9e] in linenoise:
    #include <sys/ioctl.h>
    #include <wctype.h>
    #include <poll.h>

#endif /* _WIN32 */

#include "linenoise.h"
#include "ConvertUTF.h"

and, additionally,

#if !defined(__GNUC__)
static char* strdup(const char* s)
{
    size_t slen;
    char* result;
    slen = strlen(s);
    result = (char*)malloc(slen + 1);
    if(result == NULL)
    {
        return NULL;
    }
    memcpy(result, s, slen+1);
    return result;
}

static strcasecmp(const char* instring1, const char* instring2)
{
    int rt;
    const unsigned char *ptr1;
    const unsigned char *ptr2;
    ptr1 = (const unsigned char*)instring1;
    ptr2 = (const unsigned char*)instring2;
    if(ptr1 == ptr2)
    {
        return 0;
    }
    while((rt = (std::tolower(*ptr1) - std::tolower(*ptr2++))) == 0)
    {
        if (*ptr1++ == 0)
        {
            break;
        }
    }
    return rt;
}
#endif

for strdup and strcasecmp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant