aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-07-13 02:12:47 +0200
committerdec05eba <dec05eba@protonmail.com>2020-07-13 02:12:47 +0200
commitee0d96fd180b235d4e87019d69e07cefde1e5546 (patch)
treebfbd268706e4ec616161ade371236763b9d90d68
parent63ff3eaf2bd2467255c08bf427a162f5c446b146 (diff)
Remove unecessary dummy callback
-rw-r--r--program.c35
-rw-r--r--program.h2
-rw-r--r--transmission.c6
3 files changed, 18 insertions, 25 deletions
diff --git a/program.c b/program.c
index 299b829..8e980ab 100644
--- a/program.c
+++ b/program.c
@@ -11,13 +11,6 @@
#define READ_END 0
#define WRITE_END 1
-int program_empty_callback(char *data, int size, void *userdata) {
- (void)data;
- (void)size;
- (void)userdata;
- return 0;
-}
-
int program_exec(const char **args, ProgramOutputCallback output_callback, void *userdata) {
/* 1 arguments */
if(args[0] == NULL)
@@ -60,20 +53,22 @@ int program_exec(const char **args, ProgramOutputCallback output_callback, void
char buffer[4097];
- for(;;) {
- ssize_t bytes_read = read(fd[READ_END], buffer, sizeof(buffer) - 1);
- if(bytes_read == 0) {
- break;
- } else if(bytes_read == -1) {
- int err = errno;
- fprintf(stderr, "Failed to read from pipe to program %s, error: %s\n", args[0], strerror(err));
- result = -err;
- goto cleanup;
+ if(output_callback) {
+ for(;;) {
+ ssize_t bytes_read = read(fd[READ_END], buffer, sizeof(buffer) - 1);
+ if(bytes_read == 0) {
+ break;
+ } else if(bytes_read == -1) {
+ int err = errno;
+ fprintf(stderr, "Failed to read from pipe to program %s, error: %s\n", args[0], strerror(err));
+ result = -err;
+ goto cleanup;
+ }
+
+ buffer[bytes_read] = '\0';
+ if(output_callback(buffer, bytes_read, userdata) != 0)
+ break;
}
-
- buffer[bytes_read] = '\0';
- if(output_callback && output_callback(buffer, bytes_read, userdata) != 0)
- break;
}
if(waitpid(pid, &status, 0) == -1) {
diff --git a/program.h b/program.h
index e910b78..4c93066 100644
--- a/program.h
+++ b/program.h
@@ -4,8 +4,6 @@
/* Return 0 if you want to continue reading. @data is null-terminated */
typedef int (*ProgramOutputCallback)(char *data, int size, void *userdata);
-int program_empty_callback(char *data, int size, void *userdata);
-
/*
@args need to have at least 2 arguments. The first which is the program name
and the last which is NULL, which indicates end of args
diff --git a/transmission.c b/transmission.c
index 59b136c..40552a7 100644
--- a/transmission.c
+++ b/transmission.c
@@ -16,13 +16,13 @@ static int program_buffer_write_callback(char *data, int size, void *userdata) {
int transmission_is_daemon_running() {
const char *args[] = { "transmission-remote", "-si", NULL };
- return program_exec(args, program_empty_callback, NULL);
+ return program_exec(args, NULL, NULL);
}
int transmission_start_daemon() {
/* TODO: Make seed ratio configurable */
const char *args[] = { "transmission-daemon", "--global-seedratio", "2.0", "--download-dir", NULL };
- int res = program_exec(args, program_empty_callback, NULL);
+ int res = program_exec(args, NULL, NULL);
if(res != 0)
return res;
@@ -37,7 +37,7 @@ int transmission_start_daemon() {
int transmission_add_torrent(const char *url) {
const char *args[] = { "transmission-remote", "-a", "--", url, NULL };
- return program_exec(args, program_empty_callback, NULL);
+ return program_exec(args, NULL, NULL);
}
int transmission_get_all_torrents(TorrentListCallback callback, void *userdata) {