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