paul@603 | 1 | /* |
paul@603 | 2 | * Show concatenated filesystem object contents using the client library. |
paul@603 | 3 | * |
paul@603 | 4 | * This should eventually use C library functions instead of client library |
paul@603 | 5 | * functions. |
paul@603 | 6 | * |
paul@603 | 7 | * Copyright (C) 2024 Paul Boddie <paul@boddie.org.uk> |
paul@603 | 8 | * |
paul@603 | 9 | * This program is free software; you can redistribute it and/or |
paul@603 | 10 | * modify it under the terms of the GNU General Public License as |
paul@603 | 11 | * published by the Free Software Foundation; either version 2 of |
paul@603 | 12 | * the License, or (at your option) any later version. |
paul@603 | 13 | * |
paul@603 | 14 | * This program is distributed in the hope that it will be useful, |
paul@603 | 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@603 | 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@603 | 17 | * GNU General Public License for more details. |
paul@603 | 18 | * |
paul@603 | 19 | * You should have received a copy of the GNU General Public License |
paul@603 | 20 | * along with this program; if not, write to the Free Software |
paul@603 | 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@603 | 22 | * Boston, MA 02110-1301, USA |
paul@603 | 23 | */ |
paul@603 | 24 | |
paul@603 | 25 | #include <stdio.h> |
paul@603 | 26 | |
paul@603 | 27 | |
paul@603 | 28 | |
paul@603 | 29 | /* NOTE: For inclusion in the C library: stream acquisition and access. */ |
paul@603 | 30 | |
paul@603 | 31 | #include <fsclient/client.h> |
paul@603 | 32 | #include <systypes/env.h> |
paul@603 | 33 | #include <systypes/fcntl.h> |
paul@603 | 34 | |
paul@603 | 35 | file_t *output; |
paul@603 | 36 | |
paul@603 | 37 | |
paul@603 | 38 | |
paul@603 | 39 | /* Transfer size for communication. */ |
paul@603 | 40 | |
paul@603 | 41 | static const offset_t TO_TRANSFER = 1024; |
paul@603 | 42 | |
paul@603 | 43 | |
paul@603 | 44 | |
paul@603 | 45 | /* Show an object from the filesystem. */ |
paul@603 | 46 | |
paul@603 | 47 | static int show_object(const char *path) |
paul@603 | 48 | { |
paul@603 | 49 | char *buffer[TO_TRANSFER]; |
paul@603 | 50 | file_t *file = client_open(path, O_RDONLY); |
paul@603 | 51 | offset_t nread; |
paul@603 | 52 | |
paul@603 | 53 | if (!client_opened(file)) |
paul@603 | 54 | return 1; |
paul@603 | 55 | |
paul@603 | 56 | while ((nread = client_read(file, buffer, TO_TRANSFER))) |
paul@603 | 57 | client_write(output, buffer, nread); |
paul@603 | 58 | |
paul@603 | 59 | client_close(file); |
paul@603 | 60 | |
paul@603 | 61 | return 0; |
paul@603 | 62 | } |
paul@603 | 63 | |
paul@603 | 64 | /* List objects in the filesystem image. */ |
paul@603 | 65 | |
paul@603 | 66 | int main(int argc, char *argv[]) |
paul@603 | 67 | { |
paul@603 | 68 | int i; |
paul@603 | 69 | |
paul@603 | 70 | /* NOTE: For inclusion in the C library: stream acquisition and access. */ |
paul@603 | 71 | |
paul@603 | 72 | output = client_get_stream(ENV_OUTPUT_STREAM_NAME, O_WRONLY); |
paul@603 | 73 | |
paul@603 | 74 | /* Show all specified objects. */ |
paul@603 | 75 | |
paul@603 | 76 | for (i = 1; i < argc; i++) |
paul@603 | 77 | { |
paul@603 | 78 | if (show_object(argv[i])) |
paul@603 | 79 | return 1; |
paul@603 | 80 | } |
paul@603 | 81 | |
paul@603 | 82 | /* NOTE: For inclusion in the C library: stream acquisition and access. */ |
paul@603 | 83 | |
paul@603 | 84 | client_flush(output); |
paul@603 | 85 | |
paul@603 | 86 | return 0; |
paul@603 | 87 | } |
paul@603 | 88 | |
paul@603 | 89 | /* vim: tabstop=4 expandtab shiftwidth=4 |
paul@603 | 90 | */ |