1.1 --- a/test_files/programs/clip.c Sun May 12 00:25:49 2024 +0200
1.2 +++ b/test_files/programs/clip.c Fri May 24 18:09:11 2024 +0200
1.3 @@ -19,32 +19,15 @@
1.4 * Boston, MA 02110-1301, USA
1.5 */
1.6
1.7 -#include <l4/sys/err.h>
1.8 -
1.9 #include <stdio.h>
1.10 #include <stdlib.h>
1.11 #include <string.h>
1.12
1.13 -/* NOTE: For inclusion in the C library: stream acquisition and access. */
1.14 -
1.15 -#include <fsclient/client.h>
1.16 -#include <systypes/env.h>
1.17 -#include <systypes/fcntl.h>
1.18 -
1.19 -static file_t *input, *output;
1.20 -static char output_buffer[256];
1.21 -
1.22 -#define _fprintf(file, s, ...) \
1.23 -( \
1.24 - sprintf(output_buffer, s, ##__VA_ARGS__), \
1.25 - client_write(file, output_buffer, strlen(output_buffer)) \
1.26 -)
1.27 -
1.28
1.29
1.30 /* Read a line from the file. */
1.31
1.32 -static int readline(file_t *file, int *lineno, char **start, char **end)
1.33 +static int readline(FILE *file, int *lineno, char **start, char **end)
1.34 {
1.35 static char buf[256];
1.36 static offset_t current = 0, limit = 0;
1.37 @@ -60,7 +43,7 @@
1.38
1.39 if (!limit)
1.40 {
1.41 - limit = client_read(file, buf, 256);
1.42 + limit = fread(buf, sizeof(char), 256, file);
1.43
1.44 if (!limit)
1.45 {
1.46 @@ -113,31 +96,21 @@
1.47
1.48 int main(int argc, char *argv[])
1.49 {
1.50 - file_t *file;
1.51 + FILE *file;
1.52 int lineno, startline, numlines;
1.53 char *start, *end;
1.54
1.55 - /* NOTE: For inclusion in the C library: stream acquisition and access. */
1.56 -
1.57 - input = client_get_stream(ENV_INPUT_STREAM_NAME, O_RDONLY);
1.58 - output = client_get_stream(ENV_OUTPUT_STREAM_NAME, O_WRONLY);
1.59 -
1.60 if (argc < 4)
1.61 return 1;
1.62
1.63 if (!strcmp(argv[1], "-"))
1.64 - file = input;
1.65 + file = stdin;
1.66 else
1.67 - file = client_open(argv[1], O_RDONLY);
1.68 + file = fopen(argv[1], "r");
1.69
1.70 - if (!client_opened(file))
1.71 + if (file == NULL)
1.72 {
1.73 - if (file != NULL)
1.74 - _fprintf(output, "Error: %s\n", l4sys_errtostr(file->error));
1.75 - else
1.76 - _fprintf(output, "Could not open file.\n");
1.77 -
1.78 - client_flush(output);
1.79 + fprintf(stderr, "Could not open file.\n");
1.80 return 1;
1.81 }
1.82
1.83 @@ -160,22 +133,17 @@
1.84
1.85 /* Otherwise, indicate that end-of-file occurred. */
1.86
1.87 - _fprintf(output, "EOF error at line %d.\n", lineno);
1.88 - client_flush(output);
1.89 + fprintf(stderr, "EOF error at line %d.\n", lineno);
1.90 return 1;
1.91 }
1.92
1.93 /* Emit line content while within the desired range of lines. */
1.94
1.95 if ((lineno >= startline) && (lineno < startline + numlines))
1.96 - client_write(output, start, end - start);
1.97 + fwrite(start, sizeof(char), end - start, stdout);
1.98 }
1.99
1.100 - client_close(file);
1.101 -
1.102 - /* NOTE: For inclusion in the C library: stream acquisition and access. */
1.103 -
1.104 - client_flush(output);
1.105 + fclose(file);
1.106
1.107 return 0;
1.108 }