A função dumpfile lê o conteúdo de um arquivo e o escreve em um
descritor, que pode ser a saída padrão, por exemplo.
/*
- * 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>
+#include <fcntl.h>
+#include <unistd.h>
+
int set_llong(char *str, long long *val)
{
char *end = NULL;
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;
+}
#define FMT_R "R$ %lld,%02d"
#define R(l) reais(l), centavos(l)
+int dumpfile(int fd, char *filename);
+
#endif