[netfilter-cvslog] r3393 - trunk/nfsim/core
rusty at netfilter.org
rusty at netfilter.org
Thu Dec 16 01:04:41 CET 2004
Author: rusty at netfilter.org
Date: 2004-12-16 01:04:40 +0100 (Thu, 16 Dec 2004)
New Revision: 3393
Modified:
trunk/nfsim/core/utils.c
trunk/nfsim/core/utils.h
Log:
grab_file/release_file utility functions
Modified: trunk/nfsim/core/utils.c
===================================================================
--- trunk/nfsim/core/utils.c 2004-12-15 23:20:33 UTC (rev 3392)
+++ trunk/nfsim/core/utils.c 2004-12-16 00:04:40 UTC (rev 3393)
@@ -25,6 +25,7 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
+#include <unistd.h>
#include "utils.h"
#include "log.h"
@@ -61,3 +62,28 @@
free(str);
exit(EXIT_FAILURE);
}
+
+/* This version adds one byte (for nul term) */
+void *grab_file(int fd, unsigned long *size)
+{
+ unsigned int max = 16384;
+ int ret;
+ void *buffer = malloc(max+1);
+
+ *size = 0;
+ while ((ret = read(fd, buffer + *size, max - *size)) > 0) {
+ *size += ret;
+ if (*size == max)
+ buffer = realloc(buffer, max *= 2 + 1);
+ }
+ if (ret < 0) {
+ free(buffer);
+ buffer = NULL;
+ }
+ return buffer;
+}
+
+void release_file(void *data, unsigned long size)
+{
+ free(data);
+}
Modified: trunk/nfsim/core/utils.h
===================================================================
--- trunk/nfsim/core/utils.h 2004-12-15 23:20:33 UTC (rev 3392)
+++ trunk/nfsim/core/utils.h 2004-12-16 00:04:40 UTC (rev 3393)
@@ -43,5 +43,8 @@
void barf(const char *fmt, ...) __attribute__((noreturn));
void barf_perror(const char *fmt, ...) __attribute__((noreturn));
+void *grab_file(int fd, unsigned long *size);
+void release_file(void *data, unsigned long size);
+
extern void kernelenv_init(void);
#endif /* _STDRUSTY_H */
More information about the netfilter-cvslog
mailing list