--- os2sdk/demos/examples/pipes/pp.c 2018/08/09 12:25:13 1.1 +++ os2sdk/demos/examples/pipes/pp.c 2018/08/09 12:26:10 1.1.1.2 @@ -1,8 +1,8 @@ /* - * DOSMAKEPIPE example (pp.c, needs related program pc.c). + * DosMakePipe example (pp.c, needs related program pc.c). * * Pipes are a byte stream oriented IPC mechanism which uses - * standard DOSREAD and DOSWRITE file system calls. Since file + * standard DosRead and DosWrite file system calls. Since file * handles are used to access the pipe, each process using the * pipe needs to know the handles. There are two general ways * this is done: @@ -25,10 +25,15 @@ * Compile as: cl -AL -G2 -Lp pp.c (parent process) * cl -AL -G2 -Lp pc.c (child process) * - * Copyright (C) Microsoft Corp. 1986 + * Created by Microsoft Corp. 1987 */ +#define INCL_DOSQUEUES +#define INCL_DOSFILEMGR +#define INCL_DOSPROCESS + +#include +#include #include -#include #define PSIZE 256 /* pipe buffer size */ @@ -38,23 +43,23 @@ char *pgmname = "pc.exe"; /* name of ch main() { - unsigned pread; /* pipe read handle */ - unsigned pwrite; /* pipe write handle */ - unsigned newstdin, newstdout; /* stdin as a pipe handle */ - unsigned FileHandlState; /* Used to modify handle inheritance */ + HFILE pread; /* pipe read handle */ + HFILE pwrite; /* pipe write handle */ + HFILE newstdin, newstdout; /* stdin as a pipe handle */ + USHORT FileHandlState; /* Used to modify handle inheritance */ int i; - int bytecount; /* bytes written result */ - struct ResultCodes rc2; /* double return codes for EXEC */ + USHORT bytecount; /* bytes written result */ + RESULTCODES rc2; /* double return codes for EXEC */ - DOSMAKEPIPE(&pread, &pwrite, PSIZE); /* create the pipe */ + DosMakePipe(&pread, &pwrite, PSIZE); /* create the pipe */ /* * Now close our stdin which is attached to the console, * and make it refer to the pipe instead. */ - DOSCLOSE(0); /* close stdin */ + DosClose(0); /* close stdin */ newstdin = 0; - DOSDUPHANDLE(pread, &newstdin); /* make pipe = stdin */ + DosDupHandle(pread, &newstdin); /* make pipe = stdin */ /* * Since the child process will normaly inherit the handles of * the parent we need to close the input of the pipe. If we @@ -66,31 +71,31 @@ main() * When the parent closes the pipe, any outstanding READs from the * child will return a length of 0 (EOF). */ - i = DOSQFHANDSTATE(pwrite, (unsigned far *)&FileHandlState); + i = DosQFHandState(pwrite, &FileHandlState); if (i) printf("Query of pwrite failed\n"); FileHandlState &= 0x7F88; /* Mask bits offensive to the call */ FileHandlState |= 0x080; /* Deny inheritance to child */ - i = DOSSETFHANDSTATE(pwrite, FileHandlState); + i = DosSetFHandState(pwrite, FileHandlState); if (i) printf("Set of pwrite failed, i = %x\n",i); #ifdef NOCODE - i = DOSQFHANDSTATE(pread, (unsigned far *)&FileHandlState); + i = DosQFHandState(pread, &FileHandlState); if (i) printf("Query of pread failed\n"); FileHandlState &= 0x7F88; /* Mask bits offensive to the call */ FileHandlState |= 0x080; /* Deny inheritance to child */ - i = DOSSETFHANDSTATE(pread, FileHandlState); + i = DosSetFHandState(pread, FileHandlState); if (i) printf("Set of pread failed, i = %x\n",i); #endif /* exec child program, which will inherit new stdin */ - DOSEXECPGM(exec_buf, sizeof(exec_buf), 1, (unsigned *)0L, - (unsigned *)0L, &rc2, pgmname); + DosExecPgm(exec_buf, sizeof(exec_buf), EXEC_ASYNC, (PSZ)0L, + (PSZ)0L, &rc2, pgmname); /* write 20 messages down the pipe */ printf("Writing messages to the pipe\n"); for(i = 0; i < 20; i++) - DOSWRITE(pwrite, msg, sizeof(msg) - 1, &bytecount); + DosWrite(pwrite, msg, sizeof(msg) - 1, &bytecount); - DOSCLOSE(pwrite); - DOSCLOSE(pread); + DosClose(pwrite); + DosClose(pread); printf("Parent exiting\n"); - DOSEXIT(1,0); /* Terminate and kill any lingering children */ + DosExit(EXIT_PROCESS,0); /* Terminate, kill any lingering children */ }