Basic implementation of Linux cat method. Uses open, read, write, close


Download 57.77 Kb.
Pdf ko'rish
Sana05.02.2023
Hajmi57.77 Kb.
#1167841
Bog'liq
my cat



#include  
#include  
#include  
/* 
Basic implementation of Linux cat method. 
Uses open, read, write, close. 
Does not handle options. 
*/ 
int main (int argc, char **argv) { 
int file, ch; 
// handle multiple filenames passed in. 
if (argc >= 2) { 
int i = 1; 
while (argv[i]) { 
file = open(argv[i], O_RDONLY); 
if (file < 0) { 
errno; 
return -1; 

while (read(file, &ch, 1)) { 
write(STDOUT_FILENO, &ch, 1); 

close(file); 
i++; 

} else { 
// handle pipe input. 
while (read(STDIN_FILENO, &ch, 1) > 0) { 


write(STDOUT_FILENO, &ch, 1); 


return 0; 


Download 57.77 Kb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling