@@ -191,7 +191,7 @@ fn uu_tail(settings: &Settings) -> UResult<()> {
191
191
192
192
if use_stdin {
193
193
let mut reader = BufReader :: new ( stdin ( ) ) ;
194
- unbounded_tail ( & mut reader, settings) ;
194
+ unbounded_tail ( & mut reader, settings) ? ;
195
195
196
196
// Don't follow stdin since there are no checks for pipes/FIFOs
197
197
//
@@ -230,7 +230,7 @@ fn uu_tail(settings: &Settings) -> UResult<()> {
230
230
}
231
231
} else {
232
232
let mut reader = BufReader :: new ( file) ;
233
- unbounded_tail ( & mut reader, settings) ;
233
+ unbounded_tail ( & mut reader, settings) ? ;
234
234
if settings. follow {
235
235
readers. push ( ( Box :: new ( reader) , filename) ) ;
236
236
}
@@ -239,7 +239,7 @@ fn uu_tail(settings: &Settings) -> UResult<()> {
239
239
}
240
240
241
241
if settings. follow {
242
- follow ( & mut readers[ ..] , settings) ;
242
+ follow ( & mut readers[ ..] , settings) ? ;
243
243
}
244
244
245
245
Ok ( ( ) )
@@ -342,10 +342,9 @@ pub fn uu_app() -> App<'static, 'static> {
342
342
)
343
343
}
344
344
345
- fn follow < T : BufRead > ( readers : & mut [ ( T , & String ) ] , settings : & Settings ) {
346
- assert ! ( settings. follow) ;
347
- if readers. is_empty ( ) {
348
- return ;
345
+ fn follow < T : BufRead > ( readers : & mut [ ( T , & String ) ] , settings : & Settings ) -> UResult < ( ) > {
346
+ if readers. is_empty ( ) || !settings. follow {
347
+ return Ok ( ( ) ) ;
349
348
}
350
349
351
350
let mut last = readers. len ( ) - 1 ;
@@ -372,7 +371,7 @@ fn follow<T: BufRead>(readers: &mut [(T, &String)], settings: &Settings) {
372
371
}
373
372
print ! ( "{}" , datum) ;
374
373
}
375
- Err ( err) => panic ! ( "{}" , err) ,
374
+ Err ( err) => return Err ( USimpleError :: new ( 1 , err. to_string ( ) ) ) ,
376
375
}
377
376
}
378
377
}
@@ -381,6 +380,7 @@ fn follow<T: BufRead>(readers: &mut [(T, &String)], settings: &Settings) {
381
380
break ;
382
381
}
383
382
}
383
+ Ok ( ( ) )
384
384
}
385
385
386
386
/// Iterate over bytes in the file, in reverse, until we find the
@@ -475,7 +475,7 @@ where
475
475
}
476
476
}
477
477
478
- fn unbounded_tail < T : Read > ( reader : & mut BufReader < T > , settings : & Settings ) {
478
+ fn unbounded_tail < T : Read > ( reader : & mut BufReader < T > , settings : & Settings ) -> UResult < ( ) > {
479
479
// Read through each line/char and store them in a ringbuffer that always
480
480
// contains count lines/chars. When reaching the end of file, output the
481
481
// data in the ringbuf.
@@ -487,11 +487,13 @@ fn unbounded_tail<T: Read>(reader: &mut BufReader<T>, settings: &Settings) {
487
487
}
488
488
FilterMode :: Bytes ( count) => {
489
489
for byte in unbounded_tail_collect ( reader. bytes ( ) , count, settings. beginning ) {
490
- let mut stdout = stdout ( ) ;
491
- print_byte ( & mut stdout, byte) ;
490
+ if let Err ( err) = stdout ( ) . write ( & [ byte] ) {
491
+ return Err ( USimpleError :: new ( 1 , err. to_string ( ) ) ) ;
492
+ }
492
493
}
493
494
}
494
495
}
496
+ Ok ( ( ) )
495
497
}
496
498
497
499
fn is_seekable < T : Seek > ( file : & mut T ) -> bool {
@@ -500,13 +502,6 @@ fn is_seekable<T: Seek>(file: &mut T) -> bool {
500
502
&& file. seek ( SeekFrom :: Start ( 0 ) ) . is_ok ( )
501
503
}
502
504
503
- #[ inline]
504
- fn print_byte < T : Write > ( stdout : & mut T , ch : u8 ) {
505
- if let Err ( err) = stdout. write ( & [ ch] ) {
506
- crash ! ( 1 , "{}" , err) ;
507
- }
508
- }
509
-
510
505
fn parse_num ( src : & str ) -> Result < ( usize , bool ) , ParseSizeError > {
511
506
let mut size_string = src. trim ( ) ;
512
507
let mut starting_with = false ;
0 commit comments