[llvm-commits] CVS: llvm-test/MultiSource/Applications/obsequi/obsequi.c
Reid Spencer
reid at x10sys.com
Mon Nov 27 14:39:53 PST 2006
Changes in directory llvm-test/MultiSource/Applications/obsequi:
obsequi.c updated: 1.4 -> 1.5
---
Log message:
Implement a poor-mans version of getline that hopefully works for this
program on most platforms.
---
Diffs of the changes: (+16 -3)
obsequi.c | 19 ++++++++++++++++---
1 files changed, 16 insertions(+), 3 deletions(-)
Index: llvm-test/MultiSource/Applications/obsequi/obsequi.c
diff -u llvm-test/MultiSource/Applications/obsequi/obsequi.c:1.4 llvm-test/MultiSource/Applications/obsequi/obsequi.c:1.5
--- llvm-test/MultiSource/Applications/obsequi/obsequi.c:1.4 Sat Nov 25 02:25:55 2006
+++ llvm-test/MultiSource/Applications/obsequi/obsequi.c Mon Nov 27 16:39:39 2006
@@ -34,14 +34,27 @@
#include "cppflags.h"
#include "interface.h"
-#ifndef __linux__
// LLVM: define our own getline for portability
#define getline getline_llvm
+// Crude approximation of gnu getline
ssize_t getline(char **lineptr, size_t *n, FILE *stream) {
- return getstr (lineptr, n, stream, '\n', 0, 0);
+ char buffer[4096];
+ bzero(buffer,4096);
+ ssize_t result = 0;
+ if (NULL == fgets(buffer, 4095, stream))
+ result = -1;
+ else
+ result = strlen(buffer);
+ if (result >= 0) {
+ if (*lineptr == 0 )
+ *lineptr = malloc(result+1);
+ else
+ *lineptr = realloc(*lineptr, result+1);
+ memcpy(*lineptr, buffer, result+1);
+ }
+ return result;
}
-#endif
//########################################################
// Function templates.
More information about the llvm-commits
mailing list