/*
- * Copyright (C) 2015 Thadeu Lima de Souza Cascardo <cascardo@minaslivre.org>
+ * Copyright (C) 2015-2016 Thadeu Lima de Souza Cascardo <cascardo@minaslivre.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include <errno.h>
#include <string.h>
-int set_llong(char *str, long long *val)
+#include <fcntl.h>
+#include <unistd.h>
+
+int set_llong(char *arg, long long *val)
{
char *end = NULL;
errno = 0;
- *val = strtoll(str, &end, 0);
+ *val = strtoll(arg, &end, 0);
if (end && *end)
return -EINVAL;
if (errno == ERANGE)
return 0;
}
-int set_int(char **args, int argc, int *val)
+int set_int(char *arg, int *val)
{
char *end = NULL;
- if (argc != 2)
- return -EINVAL;
errno = 0;
- *val = strtol(args[1], &end, 0);
+ *val = strtol(arg, &end, 0);
if (end && *end)
return -EINVAL;
if (errno == ERANGE)
return 0;
}
-int set_string(char **args, int argc, char **str)
+int set_string(char *arg, char **str)
{
- if (argc != 2)
- return -EINVAL;
- *str = strdup(args[1]);
+ *str = strdup(arg);
if (!*str)
return -errno;
return 0;
}
+
+int dumpfile(int fd, char *filename)
+{
+ int inp;
+ char buffer[256];
+ int r;
+ inp = open(filename, O_RDONLY);
+ if (inp < 0)
+ return -errno;
+ while ((r = read(inp, buffer, sizeof(buffer))) > 0) {
+ write(fd, buffer, r);
+ }
+ close(inp);
+ return r;
+}