/* Demo application which uses a named pipe to receive ITM data from a DLL loaded by T32 in PIPE mode. (C) Lauterbach Datentechnik GmbH 2010 */ #if defined(_MSC_VER)||defined(__MINGW32__) # define _CRT_SECURE_NO_WARNINGS 1 # include #endif #if defined(__linux__) # include # include # include # include # define INVALID_HANDLE_VALUE -1 #endif #include #include "mypipe.h" int main(int argc, char **argv) { mypipe_t handle; unsigned int i; unsigned char buf[8200]; if (argc!=2) { printf("Usage: pipe_read \n"); return 1; } #if defined(_MSC_VER)||defined(__MINGW32__) /* extract pipe name from command line parameters */ sprintf((char *)buf,"//./pipe/%s",argv[1]); #endif #if defined(__linux__) /* extract pipe name from command line parameters */ sprintf((char *)buf,"/tmp/%s",argv[1]); #endif /* Create a named pipe for reading data from it */ if (mypipe_create_read(&handle,(char *)buf,1)) { printf("Can not create %s\n",buf); return 2; } printf("Connected to %s\n",buf); do { /* read data from pipe */ i=mypipe_read(handle,buf,8100); /* stop if write end of pipe was closed */ if (i==0) break; fwrite(buf,1,i,stdout); fflush(stdout); } while(1); mypipe_close(handle); return 0; }