# HG changeset patch # User Paul Boddie # Date 1713453253 -7200 # Node ID 550396dab4dae1e31d06401cd4f889c21ed0bd4d # Parent e4d464fd40c1469976cabb8ff9a2d437383e040f Migrated some test programs to standard C library usage. diff -r e4d464fd40c1 -r 550396dab4da test_files/programs/cat.c --- a/test_files/programs/cat.c Thu Apr 18 17:13:40 2024 +0200 +++ b/test_files/programs/cat.c Thu Apr 18 17:14:13 2024 +0200 @@ -1,8 +1,5 @@ /* - * Show concatenated filesystem object contents using the client library. - * - * This should eventually use C library functions instead of client library - * functions. + * Show concatenated filesystem object contents. * * Copyright (C) 2024 Paul Boddie * @@ -26,16 +23,6 @@ -/* NOTE: For inclusion in the C library: stream acquisition and access. */ - -#include -#include -#include - -file_t *output; - - - /* Transfer size for communication. */ static const offset_t TO_TRANSFER = 1024; @@ -47,19 +34,19 @@ static int show_object(const char *path) { char *buffer[TO_TRANSFER]; - file_t *file = client_open(path, O_RDONLY); - offset_t nread; + FILE *file = fopen(path, "r"); + size_t nread; - if (!client_opened(file)) + if (file == NULL) return 1; - while ((nread = client_read(file, buffer, TO_TRANSFER))) + while ((nread = fread(buffer, sizeof(char), TO_TRANSFER, file))) { - if (!client_write(output, buffer, nread)) + if (!fwrite(buffer, sizeof(char), nread, stdout)) break; } - client_close(file); + fclose(file); return 0; } @@ -70,10 +57,6 @@ { int i; - /* NOTE: For inclusion in the C library: stream acquisition and access. */ - - output = client_get_stream(ENV_OUTPUT_STREAM_NAME, O_WRONLY); - /* Show all specified objects. */ for (i = 1; i < argc; i++) @@ -82,10 +65,6 @@ return 1; } - /* NOTE: For inclusion in the C library: stream acquisition and access. */ - - client_flush(output); - return 0; } diff -r e4d464fd40c1 -r 550396dab4da test_files/programs/ls.c --- a/test_files/programs/ls.c Thu Apr 18 17:13:40 2024 +0200 +++ b/test_files/programs/ls.c Thu Apr 18 17:14:13 2024 +0200 @@ -22,6 +22,7 @@ * Boston, MA 02110-1301, USA */ +#include #include #include #include @@ -31,29 +32,18 @@ #include /* get_permission_string */ #include +#include #include #define FMTnlinkd "%" pFMTnlink "d" -/* NOTE: For inclusion in the C library: stream acquisition and access. */ - -#include -#include -#include - -file_t *output; - - - /* Show object details. */ static void _show_object(const char *basename, struct stat *st) { - char buffer[strlen(basename) + 64]; - - sprintf(buffer, "%s%s %5d %5d %6ld " FMTnlinkd " %s\n", + printf("%s%s %5d %5d %6ld " FMTnlinkd " %s\n", S_ISDIR(st->st_mode) ? "d" : "-", get_permission_string(st->st_mode), st->st_uid, @@ -61,8 +51,6 @@ st->st_size, st->st_nlink, basename); - - client_write(output, buffer, strlen(buffer)); } /* Show an object in a directory. */ @@ -97,8 +85,11 @@ { reader = client_opendir(path); - if (reader == NULL) + if (!client_opened(reader)) + { + client_close(reader); return 1; + } /* Show the directory entries. */ @@ -127,8 +118,7 @@ { /* Emit each object's name. */ - client_write(output, path, strlen(path)); - client_write(output, "\n", 1); + printf("%s\n", path); /* List individual files or directories. */ @@ -150,10 +140,6 @@ { int i; - /* NOTE: For inclusion in the C library: stream acquisition and access. */ - - output = client_get_stream(ENV_OUTPUT_STREAM_NAME, O_WRONLY); - /* List the top level without any argument. */ if (argc < 2) @@ -172,10 +158,6 @@ } } - /* NOTE: For inclusion in the C library: stream acquisition and access. */ - - client_flush(output); - return 0; }