Skip to content

Commit

Permalink
iio_readdev: Fix corrupt data that was being captured on Windows
Browse files Browse the repository at this point in the history
The captured data is sent to stdout but during this process (on Windows)
any byte that has the same value as line feed character (LF) gets
converted to CF-LF characters. This dissrupts the alignment of bytes
that represent the samples of the device.

Fixes #257.

Signed-off-by: Dan Nechita <[email protected]>
  • Loading branch information
dNechita authored and commodo committed Feb 7, 2020
1 parent 8d4563c commit f7c5e7f
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/iio_readdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ static void quit_all(int sig)
#ifdef _WIN32

#include <windows.h>
#include <io.h>
#include <fcntl.h>

BOOL WINAPI sig_handler_fn(DWORD dwCtrlType)
{
Expand Down Expand Up @@ -378,6 +380,14 @@ int main(int argc, char **argv)
return EXIT_FAILURE;
}

#ifdef _WIN32
/*
* Deactivate the translation for the stdout. Otherwise, bytes that have
* the same value as line feed character (LF) will be translated to CR-LF.
*/
_setmode(_fileno(stdout), _O_BINARY);
#endif

while (app_running) {
int ret = iio_buffer_refill(buffer);
if (ret < 0) {
Expand Down

0 comments on commit f7c5e7f

Please sign in to comment.