what is the name of this piece of code


 
Thread Tools Search this Thread
Top Forums Programming what is the name of this piece of code
# 1  
Old 10-13-2012
Computer what is the name of this piece of code

Code:
while ((numRead = read(inputFd, buf, BUF_SIZE)) > 0)
if (write(outputFd, buf, numRead) != numRead)
fatal("couldn't write whole buffer");

if (numRead == -1)
errExit("read");

if (close(inputFd) == -1)
errExit("close input");

if (close(outputFd) == -1)
errExit("close output");

exit(EXIT_SUCCESS);

since:
Code:
#ifndef BUF_SIZE 
#define BUF_SIZE 1024
#endif
ssize_t numRead;
char buf[BUF_SIZE];
inputFd = open(argv[1], O_RDONLY);
outputFd = open(argv[2], openFlags, filePerms);

I need to understand the while loop Smilie
# 2  
Old 10-13-2012
Quote:
Originally Posted by fwrlfo
Code:
while ((numRead = read(inputFd, buf, BUF_SIZE)) > 0)
if (write(outputFd, buf, numRead) != numRead)
fatal("couldn't write whole buffer");

if (numRead == -1)
errExit("read");

if (close(inputFd) == -1)
errExit("close input");

if (close(outputFd) == -1)
errExit("close output");

exit(EXIT_SUCCESS);

... ... ...
A simple translation from C to English is:
  1. Read no more than BUF_SIZE bytes from the file associated with the file descriptor inputFd into the array of characters at the address specified by buf and save the number of bytes actually read in numRead.
  2. If numRead is greater than 0, write those bytes from buf to the file file associated with the file descriptor outputFd and return the number of bytes written.
  3. If the number of bytes written is not the same as the number of bytes read do whatever the function fatal() does.
  4. Repeat steps 1, 2, and 3 until read has no more data to read (in which case it returns 0) or detects an error (in which case it returns -1).
This User Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need a piece of shell scripting to remove column from a csv file

Hi, I need to remove first column from a csv file and i can do this by using below command. cut -f1 -d, --complement Mytest.csv I need to implement this in shell scripting, Whenever i am using the above command alone in command line it is working fine. I have 5 files in my directory and... (3 Replies)
Discussion started by: Samah
3 Replies

2. Shell Programming and Scripting

Time:Piece

Hi I am trying to find out difference between two dates with Time:Piece. I am able to get the days difference, but I want the Days as wells as hours, mins and sec difference. Below is my code for both, but the later is now working. Can anyone help me out. With only days use... (0 Replies)
Discussion started by: sauravrout
0 Replies

3. Shell Programming and Scripting

Looking for guidance (comments) on a piece of code

Hello -- I am trying to learn to do a little sed and awk scripting to search for text and numbers in text files (text processing/manipulation). My professor gave me a piece of uncommented code and I am very unfamiliar w/ the language. Can someone help me with comments so I can understand what is... (2 Replies)
Discussion started by: smithan05
2 Replies

4. War Stories

One time I fixed an LCD monitor with a folded piece of paper

Some of the colors weren't working on the Monitor. I found pressing around the plastic border of the screen brought them back. I opened the monitor casing and used the folded paper to put pressure against the LCD panel and housing. Wah Lah. More of a bend than a hack I guess. (2 Replies)
Discussion started by: herot
2 Replies

5. Shell Programming and Scripting

Need help optimizing this piece of code (Shell script Busybox)

I am looking for suggestions on how I could possibly optimized that piece of code where most of the time is spend on this script. In a nutshell this is a script that creates an xml file(s) based on certain criteria that will be used by a movie jukebox. Example of data: $SORTEDTMP= it is a... (16 Replies)
Discussion started by: snappy46
16 Replies

6. Shell Programming and Scripting

script or piece of code where the data returned by a stored procedure you are writing

hi fndz. Can you please help me with the code if I call a stored procedure from my shell script and stored procedure returns a cursor, cursor output should be saved to a file (3 Replies)
Discussion started by: enigma_83
3 Replies

7. Shell Programming and Scripting

How to extract a piece of information from a huge file

Hello All, I need some assistance to extract a piece of information from a huge file. The file is like this one : database information ccccccccccccccccc ccccccccccccccccc ccccccccccccccccc ccccccccccccccccc os information cccccccccccccccccc cccccccccccccccccc... (2 Replies)
Discussion started by: Marcor
2 Replies

8. Shell Programming and Scripting

what does this piece of code do?

Hi All, I am trying to understand and change some code written by some programmer a while ago. There are following three lines of code that I am unable to grasp. Could anybody please help me understand it? 1) cd - > /dev/null 2) fname=`basename "$1"` where $1 = /dirA/dirB/a.txt ... (3 Replies)
Discussion started by: Vikas Sood
3 Replies

9. Shell Programming and Scripting

a piece of code, plz help to review

use "getopts" to get params from command. Need replace black with a specified string like "%20 DEFAULT_DELIM=%20 ... while getopts dek:f:t:vh OPTION do case $OPTION in t) DELIM=`tvar=/'"$OPTARG"'/ svar="$DEFAULT_DELIM" awk 'BEGIN{T=ENVIRON;S=ENVIRON; while(index(T,S)!=0){S=S"0"};print... (0 Replies)
Discussion started by: anypager
0 Replies
Login or Register to Ask a Question