| File: | _build/../src/slowcat.c |
| Warning: | line 106, column 4 This statement is never executed |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* |
| 2 | * Copyright (C) 2002 Red Hat, Inc. |
| 3 | * |
| 4 | * This library is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU Lesser General Public |
| 6 | * License as published by the Free Software Foundation; either |
| 7 | * version 2.1 of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * This library is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | * Lesser General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Lesser General Public |
| 15 | * License along with this library; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 17 | */ |
| 18 | |
| 19 | #include <config.h> |
| 20 | #include <sys/time.h> |
| 21 | #include <sys/types.h> |
| 22 | #include <errno(*__errno_location ()).h> |
| 23 | #include <signal.h> |
| 24 | #include <stdbool.h> |
| 25 | #include <stdio.h> |
| 26 | #include <stdlib.h> |
| 27 | #include <string.h> |
| 28 | #include <unistd.h> |
| 29 | #include <glib.h> |
| 30 | |
| 31 | static void |
| 32 | catfile(const char *pathname, long delay, long chunksize) |
| 33 | { |
| 34 | FILE *fp; |
| 35 | struct timeval tv; |
| 36 | char *buf; |
| 37 | int c; |
| 38 | long i; |
| 39 | bool_Bool is_opened = FALSE(0); |
| 40 | |
| 41 | if (!((pathname == NULL((void*)0)) || (strcmp(pathname, "-") == 0))) { |
| 42 | fp = fopen(pathname, "r"); |
| 43 | is_opened = TRUE(!(0)); |
| 44 | if (fp == NULL((void*)0)) { |
| 45 | g_warning("Error opening file `%s': %s.\n", |
| 46 | pathname, strerror(errno(*__errno_location ()))); |
| 47 | return; |
| 48 | } |
| 49 | } else { |
| 50 | fp = stdinstdin; |
| 51 | } |
| 52 | |
| 53 | buf = g_malloc(chunksize); |
| 54 | |
| 55 | while (!feof(fp)) { |
| 56 | tv.tv_sec = delay / 1000000; |
| 57 | tv.tv_usec = delay % 1000000; |
| 58 | select(0, NULL((void*)0), NULL((void*)0), NULL((void*)0), &tv); |
| 59 | for (i = 0; i < chunksize; i++) { |
| 60 | c = fgetc(fp); |
| 61 | if (c != EOF(-1)) { |
| 62 | buf[i] = c; |
| 63 | } else { |
| 64 | break; |
| 65 | } |
| 66 | } |
| 67 | if (i > 0) { |
| 68 | int bytes G_GNUC_UNUSED__attribute__ ((__unused__)); |
| 69 | bytes = write(STDOUT_FILENO1, buf, i); |
| 70 | fsync(STDOUT_FILENO1); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | g_free(buf); |
| 75 | |
| 76 | if (is_opened) { |
| 77 | fclose(fp); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | int |
| 82 | main(int argc, char **argv) |
| 83 | { |
| 84 | int i, c; |
| 85 | long delay = 200000, chunksize = 1, tmp; |
| 86 | char *p; |
| 87 | GList *files = NULL((void*)0); |
| 88 | |
| 89 | while ((c = getopt(argc, argv, "t:c:")) != -1) { |
| 90 | switch (c) { |
| 91 | case 't': |
| 92 | tmp = strtol(optarg, &p, 0); |
| 93 | if ((p != NULL((void*)0)) && (*p == '\0')) { |
| 94 | delay = tmp; |
| 95 | } |
| 96 | break; |
| 97 | case 'c': |
| 98 | tmp = strtol(optarg, &p, 0); |
| 99 | if ((p != NULL((void*)0)) && (*p == '\0')) { |
| 100 | chunksize = tmp; |
| 101 | } |
| 102 | break; |
| 103 | default: |
| 104 | g_printerr("Usage: slowcat [-t delay] [-c chunksize] [file ...]\n"); |
| 105 | exit(1); |
| 106 | break; |
This statement is never executed | |
| 107 | } |
| 108 | } |
| 109 | for (i = optind; i < argc; i++) { |
| 110 | files = g_list_append(files, argv[i]); |
| 111 | } |
| 112 | |
| 113 | if (files) { |
| 114 | GList *file; |
| 115 | for (file = files; file != NULL((void*)0); file = g_list_next(file)((file) ? (((GList *)(file))->next) : ((void*)0))) { |
| 116 | catfile((const char*)file->data, delay, chunksize); |
| 117 | } |
| 118 | } else { |
| 119 | catfile(NULL((void*)0), delay, chunksize); |
| 120 | } |
| 121 | return 0; |
| 122 | } |