1.1 --- a/test_files/programs/cat.c Thu Apr 18 17:13:40 2024 +0200
1.2 +++ b/test_files/programs/cat.c Thu Apr 18 17:14:13 2024 +0200
1.3 @@ -1,8 +1,5 @@
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 + * Show concatenated filesystem object contents.
1.10 *
1.11 * Copyright (C) 2024 Paul Boddie <paul@boddie.org.uk>
1.12 *
1.13 @@ -26,16 +23,6 @@
1.14
1.15
1.16
1.17 -/* NOTE: For inclusion in the C library: stream acquisition and access. */
1.18 -
1.19 -#include <fsclient/client.h>
1.20 -#include <systypes/env.h>
1.21 -#include <systypes/fcntl.h>
1.22 -
1.23 -file_t *output;
1.24 -
1.25 -
1.26 -
1.27 /* Transfer size for communication. */
1.28
1.29 static const offset_t TO_TRANSFER = 1024;
1.30 @@ -47,19 +34,19 @@
1.31 static int show_object(const char *path)
1.32 {
1.33 char *buffer[TO_TRANSFER];
1.34 - file_t *file = client_open(path, O_RDONLY);
1.35 - offset_t nread;
1.36 + FILE *file = fopen(path, "r");
1.37 + size_t nread;
1.38
1.39 - if (!client_opened(file))
1.40 + if (file == NULL)
1.41 return 1;
1.42
1.43 - while ((nread = client_read(file, buffer, TO_TRANSFER)))
1.44 + while ((nread = fread(buffer, sizeof(char), TO_TRANSFER, file)))
1.45 {
1.46 - if (!client_write(output, buffer, nread))
1.47 + if (!fwrite(buffer, sizeof(char), nread, stdout))
1.48 break;
1.49 }
1.50
1.51 - client_close(file);
1.52 + fclose(file);
1.53
1.54 return 0;
1.55 }
1.56 @@ -70,10 +57,6 @@
1.57 {
1.58 int i;
1.59
1.60 - /* NOTE: For inclusion in the C library: stream acquisition and access. */
1.61 -
1.62 - output = client_get_stream(ENV_OUTPUT_STREAM_NAME, O_WRONLY);
1.63 -
1.64 /* Show all specified objects. */
1.65
1.66 for (i = 1; i < argc; i++)
1.67 @@ -82,10 +65,6 @@
1.68 return 1;
1.69 }
1.70
1.71 - /* NOTE: For inclusion in the C library: stream acquisition and access. */
1.72 -
1.73 - client_flush(output);
1.74 -
1.75 return 0;
1.76 }
1.77
2.1 --- a/test_files/programs/ls.c Thu Apr 18 17:13:40 2024 +0200
2.2 +++ b/test_files/programs/ls.c Thu Apr 18 17:14:13 2024 +0200
2.3 @@ -22,6 +22,7 @@
2.4 * Boston, MA 02110-1301, USA
2.5 */
2.6
2.7 +#include <dirent.h>
2.8 #include <stdio.h>
2.9 #include <stdlib.h>
2.10 #include <string.h>
2.11 @@ -31,29 +32,18 @@
2.12
2.13 #include <e2access/format.h> /* get_permission_string */
2.14 #include <e2access/path.h>
2.15 +#include <fsclient/client.h>
2.16 #include <systypes/format.h>
2.17
2.18 #define FMTnlinkd "%" pFMTnlink "d"
2.19
2.20
2.21
2.22 -/* NOTE: For inclusion in the C library: stream acquisition and access. */
2.23 -
2.24 -#include <fsclient/client.h>
2.25 -#include <systypes/env.h>
2.26 -#include <systypes/fcntl.h>
2.27 -
2.28 -file_t *output;
2.29 -
2.30 -
2.31 -
2.32 /* Show object details. */
2.33
2.34 static void _show_object(const char *basename, struct stat *st)
2.35 {
2.36 - char buffer[strlen(basename) + 64];
2.37 -
2.38 - sprintf(buffer, "%s%s %5d %5d %6ld " FMTnlinkd " %s\n",
2.39 + printf("%s%s %5d %5d %6ld " FMTnlinkd " %s\n",
2.40 S_ISDIR(st->st_mode) ? "d" : "-",
2.41 get_permission_string(st->st_mode),
2.42 st->st_uid,
2.43 @@ -61,8 +51,6 @@
2.44 st->st_size,
2.45 st->st_nlink,
2.46 basename);
2.47 -
2.48 - client_write(output, buffer, strlen(buffer));
2.49 }
2.50
2.51 /* Show an object in a directory. */
2.52 @@ -97,8 +85,11 @@
2.53 {
2.54 reader = client_opendir(path);
2.55
2.56 - if (reader == NULL)
2.57 + if (!client_opened(reader))
2.58 + {
2.59 + client_close(reader);
2.60 return 1;
2.61 + }
2.62
2.63 /* Show the directory entries. */
2.64
2.65 @@ -127,8 +118,7 @@
2.66 {
2.67 /* Emit each object's name. */
2.68
2.69 - client_write(output, path, strlen(path));
2.70 - client_write(output, "\n", 1);
2.71 + printf("%s\n", path);
2.72
2.73 /* List individual files or directories. */
2.74
2.75 @@ -150,10 +140,6 @@
2.76 {
2.77 int i;
2.78
2.79 - /* NOTE: For inclusion in the C library: stream acquisition and access. */
2.80 -
2.81 - output = client_get_stream(ENV_OUTPUT_STREAM_NAME, O_WRONLY);
2.82 -
2.83 /* List the top level without any argument. */
2.84
2.85 if (argc < 2)
2.86 @@ -172,10 +158,6 @@
2.87 }
2.88 }
2.89
2.90 - /* NOTE: For inclusion in the C library: stream acquisition and access. */
2.91 -
2.92 - client_flush(output);
2.93 -
2.94 return 0;
2.95 }
2.96