1// Copyright 2016 The Fuchsia Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include <fcntl.h> 6#include <stdio.h> 7#include <unistd.h> 8 9int main(int argc, char** argv) { 10 unsigned char x; 11 int fd = 0; 12 if (argc == 2) { 13 fd = open(argv[1], O_RDONLY); 14 if (fd < 0) { 15 printf("dump1: cannot open '%s'\n", argv[1]); 16 return -1; 17 } 18 } 19 for (;;) { 20 int r = read(fd, &x, 1); 21 if (r == 0) { 22 continue; 23 } 24 if (r != 1) { 25 break; 26 } 27 if (x == 'z') { 28 break; 29 } 30 printf("%02x ", x); 31 fflush(stdout); 32 } 33 printf("\n"); 34 return 0; 35} 36