1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/test_files/programs/cat.c Wed Jan 17 00:53:05 2024 +0100
1.3 @@ -0,0 +1,90 @@
1.4 +/*
1.5 + * Show concatenated filesystem object contents using the client library.
1.6 + *
1.7 + * This should eventually use C library functions instead of client library
1.8 + * functions.
1.9 + *
1.10 + * Copyright (C) 2024 Paul Boddie <paul@boddie.org.uk>
1.11 + *
1.12 + * This program is free software; you can redistribute it and/or
1.13 + * modify it under the terms of the GNU General Public License as
1.14 + * published by the Free Software Foundation; either version 2 of
1.15 + * the License, or (at your option) any later version.
1.16 + *
1.17 + * This program is distributed in the hope that it will be useful,
1.18 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.19 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.20 + * GNU General Public License for more details.
1.21 + *
1.22 + * You should have received a copy of the GNU General Public License
1.23 + * along with this program; if not, write to the Free Software
1.24 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
1.25 + * Boston, MA 02110-1301, USA
1.26 + */
1.27 +
1.28 +#include <stdio.h>
1.29 +
1.30 +
1.31 +
1.32 +/* NOTE: For inclusion in the C library: stream acquisition and access. */
1.33 +
1.34 +#include <fsclient/client.h>
1.35 +#include <systypes/env.h>
1.36 +#include <systypes/fcntl.h>
1.37 +
1.38 +file_t *output;
1.39 +
1.40 +
1.41 +
1.42 +/* Transfer size for communication. */
1.43 +
1.44 +static const offset_t TO_TRANSFER = 1024;
1.45 +
1.46 +
1.47 +
1.48 +/* Show an object from the filesystem. */
1.49 +
1.50 +static int show_object(const char *path)
1.51 +{
1.52 + char *buffer[TO_TRANSFER];
1.53 + file_t *file = client_open(path, O_RDONLY);
1.54 + offset_t nread;
1.55 +
1.56 + if (!client_opened(file))
1.57 + return 1;
1.58 +
1.59 + while ((nread = client_read(file, buffer, TO_TRANSFER)))
1.60 + client_write(output, buffer, nread);
1.61 +
1.62 + client_close(file);
1.63 +
1.64 + return 0;
1.65 +}
1.66 +
1.67 +/* List objects in the filesystem image. */
1.68 +
1.69 +int main(int argc, char *argv[])
1.70 +{
1.71 + int i;
1.72 +
1.73 + /* NOTE: For inclusion in the C library: stream acquisition and access. */
1.74 +
1.75 + output = client_get_stream(ENV_OUTPUT_STREAM_NAME, O_WRONLY);
1.76 +
1.77 + /* Show all specified objects. */
1.78 +
1.79 + for (i = 1; i < argc; i++)
1.80 + {
1.81 + if (show_object(argv[i]))
1.82 + return 1;
1.83 + }
1.84 +
1.85 + /* NOTE: For inclusion in the C library: stream acquisition and access. */
1.86 +
1.87 + client_flush(output);
1.88 +
1.89 + return 0;
1.90 +}
1.91 +
1.92 +/* vim: tabstop=4 expandtab shiftwidth=4
1.93 +*/