1 /* 2 * Show concatenated filesystem object contents. 3 * 4 * Copyright (C) 2024 Paul Boddie <paul@boddie.org.uk> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of 9 * the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA 20 */ 21 22 #include <stdio.h> 23 24 25 26 /* Transfer size for communication. */ 27 28 static const offset_t TO_TRANSFER = 1024; 29 30 31 32 /* Show an object from the filesystem. */ 33 34 static int show_object(const char *path) 35 { 36 char *buffer[TO_TRANSFER]; 37 FILE *file = fopen(path, "r"); 38 size_t nread; 39 40 if (file == NULL) 41 return 1; 42 43 while ((nread = fread(buffer, sizeof(char), TO_TRANSFER, file))) 44 { 45 if (!fwrite(buffer, sizeof(char), nread, stdout)) 46 break; 47 } 48 49 fclose(file); 50 51 return 0; 52 } 53 54 /* List objects in the filesystem image. */ 55 56 int main(int argc, char *argv[]) 57 { 58 int i; 59 60 /* Show all specified objects. */ 61 62 for (i = 1; i < argc; i++) 63 { 64 if (show_object(argv[i])) 65 return 1; 66 } 67 68 return 0; 69 } 70 71 /* vim: tabstop=4 expandtab shiftwidth=4 72 */