take a filenum instead of a file pointer.
This commit is contained in:
parent
4a9ab4f9f3
commit
c752033121
7
wc.c
7
wc.c
|
@ -2,10 +2,10 @@
|
|||
#include <unistd.h> // read, isatty
|
||||
|
||||
// STDIN_FILENO
|
||||
int process_fp(FILE* fp)
|
||||
int process_fp(int filenum)
|
||||
{
|
||||
char buffer[1];
|
||||
while (read(0, buffer, sizeof(buffer)) > 0) {
|
||||
while (read(filenum, buffer, sizeof(buffer)) > 0) {
|
||||
printf("%c", buffer[0]);
|
||||
}
|
||||
return 0;
|
||||
|
@ -13,8 +13,7 @@ int process_fp(FILE* fp)
|
|||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
//
|
||||
if (!isatty(STDIN_FILENO)) { // check if stdin is coming from terminal or pipeline
|
||||
if (!isatty(STDIN_FILENO)) {
|
||||
return process_fp(STDIN_FILENO);
|
||||
} else if(argc > 1){
|
||||
printf("To do");
|
||||
|
|
Loading…
Reference in New Issue
Block a user