summaryrefslogtreecommitdiff
path: root/libbb/read_package_field.c
blob: 4ba0bc6024f32ca51df4cde65979b23a9d1f4f72 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//#include <stdio.h>
#include <string.h>
#include "libbb.h"

/*
 * Returns a [multi-line] package field
 */
extern char *read_package_field(const char *package_buffer)
{
	char *field = NULL;
	int field_length = 0;	
	int buffer_length = 0;

	buffer_length = strlen(package_buffer);
	field = xcalloc(1, buffer_length + 1);

	while ((field = strchr(&package_buffer[field_length], '\n')) != NULL) {
		field_length = buffer_length - strlen(field);
		if (package_buffer[field_length + 1] != ' ') {
			break;
		} else {
			field_length++;
		}		
	}
	if (field_length == 0) {
		return(NULL);
	} else {
		return(xstrndup(package_buffer, field_length));
	}
}