Skip to contentSkip to conversation

Implement bt_getline

PATCH New Mathieu Desnoyers 1 participant 1 message Oct 13, 2015 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 2/2 Implement bt_getline

Implement our own getline to remove dependency from glibc 2.10+ and to increase portability to other operating systems.

---
 converter/babeltrace-log.c        |   5 +-
 include/babeltrace/compat/stdio.h | 124 ++++++++++++++++++++++++++++++++++++++
 tests/lib/test_ctf_writer.c       |   7 ++-
 3 files changed, 130 insertions(+), 6 deletions(-)
 create mode 100644 include/babeltrace/compat/stdio.h
converter/babeltrace-log.c +2 -3
index 5900b32..acbd0ee 100644
@@ -24,8 +24,6 @@
  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  * SOFTWARE.
- *
- * Depends on glibc 2.10 for getline().
  */
 
 #define _GNU_SOURCE
@@ -47,6 +45,7 @@
 #include <babeltrace/ctf/types.h>
 #include <babeltrace/compat/uuid.h>
 #include <babeltrace/compat/utc.h>
+#include <babeltrace/compat/stdio.h>
 #include <babeltrace/endian.h>
 
 #define NSEC_PER_USEC 1000UL
@@ -331,7 +330,7 @@ void trace_text(FILE *input, int output)
 	write_packet_header(&pos, s_uuid);
 	write_packet_context(&pos);
 	for (;;) {
-		len = getline(&line, &linesize, input);
+		len = bt_getline(&line, &linesize, input);
 		if (len < 0)
 			break;
 		nl = strrchr(line, '\n');
include/babeltrace/compat/stdio.h new file +124 -0

124 lines not on this page · raw message

tests/lib/test_ctf_writer.c +4 -3
index b626a66..91ef81a 100644
@@ -35,6 +35,7 @@
 #include <stdio.h>
 #include <sys/utsname.h>
 #include <babeltrace/compat/limits.h>
+#include <babeltrace/compat/stdio.h>
 #include <string.h>
 #include <assert.h>
 #include <sys/wait.h>
@@ -160,12 +161,12 @@ result:
 		rewind(metadata_fp);
 
 		/* Output the metadata and parser output as diagnostic */
-		while (getline(&line, &len, metadata_fp) > 0) {
+		while (bt_getline(&line, &len, metadata_fp) > 0) {
 			fprintf(stderr, "# %s", line);
 		}
 
 		rewind(parser_output_fp);
-		while (getline(&line, &len, parser_output_fp) > 0) {
+		while (bt_getline(&line, &len, parser_output_fp) > 0) {
 			fprintf(stderr, "# %s", line);
 		}
 
@@ -257,7 +258,7 @@ result:
 			diag("malloc error");
 		}
 		rewind(babeltrace_output_fp);
-		while (getline(&line, &len, babeltrace_output_fp) > 0) {
+		while (bt_getline(&line, &len, babeltrace_output_fp) > 0) {
 			diag("%s", line);
 		}
 
Signature · 1 line
2.1.4