2011/10/4 Eric Pouech <[email protected]>: > > > Le 4 octobre 2011 13:40, Frédéric Delanoy <[email protected]> a > écrit : >> >> 2011/10/4 Dan Kegel <[email protected]>: >> > + * handle_type: type of hIn handle >> > + * 0 if file, 1 if console, anything else if unknown >> > (autodetect) >> > >> > I suspect you want an enum for that. >> >> Well I thought about that, but found it a bit overkill for such a >> limited set of possible values. >> Also, if I used sthg like >> >> enum CMD_HANDLE_TYPE { >> CMD_HT_FILE = 0, >> CMD_HT_CONSOLE = 1, >> CMD_HT_UNKNOWN = 2 >> } >> > again, this is not needed (passing all thoses CMD_HT bits) > > static inline BOOL is_console_handle(HANDLE h) {return ((DWORD_PTR)h) & 3 == > 3;} > will test every handle and tell whether it's a console or a regular (file, > pipe...) handle > > Eric Pouech
OK but the purpose is to avoid checking the handle type for every line read. Granted, one could use '((DWORD_PTR)h) & 3 == 3' instead of GetConsoleMode or similar function. (there's currently code like "BOOL is_console = GetConsoleMode(...); ...; while WCMD_fgets(..., is_console)" and the handle type shouldn't change between lines/iterations, so why bother recomputing it every time?)
