c - How to rewind a file descriptor using only system calls? -


i have sample code i'm trying implement operating systems assignment program copies contents of input file output file. i'm allowed use posix system calls, stdio forbidden. i've thought storing contents in buffer in implementation must know file descriptor contents size. googled little , found about

off_t fsize; fsize = lseek (input, 0, seek_end); 

but in case file descriptor (input) gets messed , can't rewind start. played around parameters can't figure way rewind first character in file after using lseek. that's thing need, having can loop byte byte , copy contents of input output.

my code here, it's short in case of want have take look:

https://github.com/lucas-sartm/osassignments/blob/master/copymachine.c

i figured out trial , error. needed read documentation , take @ read() return values... loop solved issue.

while (read (input, &content, sizeof(content)) > 0){ //this write byte byte until end of buffer!       write (output, &content, sizeof(content));  } 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -