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