Skip to content

Commit

Permalink
Don't use strchrnul(), which is a glibc extension.
Browse files Browse the repository at this point in the history
Not compatible with other platforms.
  • Loading branch information
hzeller committed Dec 22, 2023
1 parent b720024 commit dad55e0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
make -k
BuildMac:
name: Install Dependencies and Build
name: Build Mac
runs-on: macos-latest
steps:
- name: Get the Source
Expand Down
13 changes: 9 additions & 4 deletions machine-connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ static bool SetTTYSpeed(tty_termios_t *tty, int speed_number) {
case 57600: speed = B57600; break;
case 115200: speed = B115200; break;
case 230400: speed = B230400; break;
#ifdef B460800
case 460800: speed = B460800; break;
#endif
default:
fprintf(stderr,
"Invalid speed '%d'; valid speeds are "
Expand Down Expand Up @@ -227,14 +229,17 @@ int OpenTCPSocket(const char *host) {
return fd;
}

static int OpenTTY(const char *descriptor) {
const char *comma = strchrnul(descriptor, ',');
const std::string path(descriptor, comma);
static int OpenTTY(std::string_view descriptor) {
auto first_comma = descriptor.find(',');
const std::string path(descriptor.substr(0, first_comma));
const std::string_view tty_params =
(first_comma != std::string_view::npos)
? descriptor.substr(first_comma + 1) : "";
const int fd = open(path.c_str(), O_RDWR | O_NOCTTY | O_SYNC);
if (fd < 0) {
return -1;
}
if (!SetTTYParams(fd, *comma ? comma + 1 : "")) {
if (!SetTTYParams(fd, tty_params)) {
return -1;
}
return fd;
Expand Down

0 comments on commit dad55e0

Please sign in to comment.