# HG changeset patch # User Paul Boddie # Date 1716566951 -7200 # Node ID c65fec5dfffb6980906e7c9da7089976c795a646 # Parent 3661a399d7351b4e18b4eeb78a35644f704b388b Converted the clip example to regular standard C library usage. diff -r 3661a399d735 -r c65fec5dfffb test_files/programs/clip.c --- a/test_files/programs/clip.c Sun May 12 00:25:49 2024 +0200 +++ b/test_files/programs/clip.c Fri May 24 18:09:11 2024 +0200 @@ -19,32 +19,15 @@ * Boston, MA 02110-1301, USA */ -#include - #include #include #include -/* NOTE: For inclusion in the C library: stream acquisition and access. */ - -#include -#include -#include - -static file_t *input, *output; -static char output_buffer[256]; - -#define _fprintf(file, s, ...) \ -( \ - sprintf(output_buffer, s, ##__VA_ARGS__), \ - client_write(file, output_buffer, strlen(output_buffer)) \ -) - /* Read a line from the file. */ -static int readline(file_t *file, int *lineno, char **start, char **end) +static int readline(FILE *file, int *lineno, char **start, char **end) { static char buf[256]; static offset_t current = 0, limit = 0; @@ -60,7 +43,7 @@ if (!limit) { - limit = client_read(file, buf, 256); + limit = fread(buf, sizeof(char), 256, file); if (!limit) { @@ -113,31 +96,21 @@ int main(int argc, char *argv[]) { - file_t *file; + FILE *file; int lineno, startline, numlines; char *start, *end; - /* NOTE: For inclusion in the C library: stream acquisition and access. */ - - input = client_get_stream(ENV_INPUT_STREAM_NAME, O_RDONLY); - output = client_get_stream(ENV_OUTPUT_STREAM_NAME, O_WRONLY); - if (argc < 4) return 1; if (!strcmp(argv[1], "-")) - file = input; + file = stdin; else - file = client_open(argv[1], O_RDONLY); + file = fopen(argv[1], "r"); - if (!client_opened(file)) + if (file == NULL) { - if (file != NULL) - _fprintf(output, "Error: %s\n", l4sys_errtostr(file->error)); - else - _fprintf(output, "Could not open file.\n"); - - client_flush(output); + fprintf(stderr, "Could not open file.\n"); return 1; } @@ -160,22 +133,17 @@ /* Otherwise, indicate that end-of-file occurred. */ - _fprintf(output, "EOF error at line %d.\n", lineno); - client_flush(output); + fprintf(stderr, "EOF error at line %d.\n", lineno); return 1; } /* Emit line content while within the desired range of lines. */ if ((lineno >= startline) && (lineno < startline + numlines)) - client_write(output, start, end - start); + fwrite(start, sizeof(char), end - start, stdout); } - client_close(file); - - /* NOTE: For inclusion in the C library: stream acquisition and access. */ - - client_flush(output); + fclose(file); return 0; }