-//#include <stdio.h>
-//#include <stdlib.h>
-//#include <string.h>
-//#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
#include "cmd.h"
#define BUFFERSIZE 4096
-static char *_load_file (FILE *fd)
+static char *_read_stream (FILE *sd)
{
char *buffer = NULL;
size_t size = 0;
size += BUFFERSIZE + (size == 0);
buffer = (char *) realloc (buffer, size);
memset (buffer + size - BUFFERSIZE - 1, 0, BUFFERSIZE + 1);
- fread (buffer + size - BUFFERSIZE - 1, 1, BUFFERSIZE, fp);
- } while (!feof (fp));
+ fread (buffer + size - BUFFERSIZE - 1, 1, BUFFERSIZE, sd);
+ } while (!feof (sd));
return buffer;
}
FILE *fp = popen (cmd, "r");
if (fp != NULL) {
- buffer = _load_file (fp);
+ buffer = _read_stream (fp);
status = pclose(fp);
}
return buffer;
}
-char *load_cmd (char *name)
+char *load_file (char *name)
{
int status = -1;
char *buffer = NULL;
FILE *fd = fopen (name, "r");
if (fd != NULL) {
- buffer = _load_file (fd);
+ buffer = _read_stream (fd);
status = fclose (fd);
}
char *read_stdin (void)
{
- int status = -1;
char *buffer = NULL;
- buffer = _load_file (stdin);
+ buffer = _read_stream (stdin);
return buffer;
}
void free_lines (char **lines)
{
int i = 0;
+
while (lines[i]) {
free (lines[i++]);
}
free (lines);
-
- return rc;
}