bin/dd/position.c
/*
 * Position input/output data streams before starting the copy.  Device type
 * dependent.  Seekable devices use lseek, and the rest position by reading.
 * Seeking past the end of file can cause null blocks to be written to the
 * output.
 */
Position input/output data streams before starting the copy.  Device type
dependent.  Seekable devices use lseek, and the rest position by reading.
Seeking past the end of file can cause null blocks to be written to the
output.
Position input / output data streams before starting the copy . Device type dependent . Seekable devices use lseek and the rest position by reading . Seeking past the end of file can cause null blocks to be written to the output .
void
pos_in()
{
	int bcnt, cnt, nr, warned;
	if (!(in.flags & (ISCHR|ISPIPE|ISTAPE))) {
		if (lseek(in.fd, (off_t)(in.offset * in.dbsz), SEEK_CUR) == -1)
			err(1, "%s", in.name);
		return;
	}
	for (bcnt = in.dbsz, cnt = in.offset, warned = 0; cnt;) {
		if ((nr = read(in.fd, in.db, bcnt)) > 0) {
			if (in.flags & ISPIPE) {
				if (!(bcnt -= nr)) {
					bcnt = in.dbsz;
					--cnt;
				}
			} else
				--cnt;
			continue;
		}
		if (nr == 0) {
			if (files_cnt > 1) {
				--files_cnt;
				continue;
			}
			errx(1, "skip reached end of input");
		}
		if (ddflags & C_NOERROR) {
			if (!warned) {
				warn("%s", in.name);
				warned = 1;
				summary();
			}
			continue;
		}
		err(1, "%s", in.name);
	}
}
void pos_in ( ) { int bcnt , cnt , nr , warned ; if ( ! ( in . flags & ( ISCHR | ISPIPE | ISTAPE ) ) ) { if ( lseek ( in . fd , ( off_t ) ( in . offset * in . dbsz ) , SEEK_CUR ) == -1 ) err ( 1 , " " , in . name ) ; return ; } for ( bcnt = in . dbsz , cnt = in . offset , warned = 0 ; cnt ; ) { if ( ( nr = read ( in . fd , in . db , bcnt ) ) > 0 ) { if ( in . flags & ISPIPE ) { if ( ! ( bcnt -= nr ) ) { bcnt = in . dbsz ; -- cnt ; } } else -- cnt ; continue ; } if ( nr == 0 ) { if ( files_cnt > 1 ) { -- files_cnt ; continue ; } errx ( 1 , " " ) ; } if ( ddflags & C_NOERROR ) { if ( ! warned ) { warn ( " " , in . name ) ; warned = 1 ; summary ( ) ; } continue ; } err ( 1 , " " , in . name ) ; } }
Position input/output data streams before starting the copy.
Position input / output data streams before starting the copy .
/* If not a character, pipe or tape device, try to seek on it. */ /*
	 * Read the data.  If a pipe, read until satisfy the number of bytes
	 * being skipped.  No differentiation for reading complete and partial
	 * blocks for other devices.
	 */ /*
		 * Input error -- either EOF with no more files, or I/O error.
		 * If noerror not set die.  POSIX requires that the warning
		 * message be followed by an I/O display.
		 */