Glenn L McGrath | 5faef74 | 2001-04-15 12:38:12 +0000 | [diff] [blame] | 1 | //#include <stdio.h> |
| 2 | #include <string.h> |
| 3 | #include "libbb.h" |
| 4 | |
| 5 | /* |
| 6 | * Returns a [multi-line] package field |
| 7 | */ |
| 8 | extern char *read_package_field(const char *package_buffer) |
| 9 | { |
| 10 | char *field = NULL; |
| 11 | int field_length = 0; |
| 12 | int buffer_length = 0; |
| 13 | |
| 14 | buffer_length = strlen(package_buffer); |
| 15 | field = xcalloc(1, buffer_length + 1); |
| 16 | |
| 17 | while ((field = strchr(&package_buffer[field_length], '\n')) != NULL) { |
| 18 | field_length = buffer_length - strlen(field); |
| 19 | if (package_buffer[field_length + 1] != ' ') { |
| 20 | break; |
| 21 | } else { |
| 22 | field_length++; |
| 23 | } |
| 24 | } |
| 25 | if (field_length == 0) { |
| 26 | return(NULL); |
| 27 | } else { |
| 28 | return(xstrndup(package_buffer, field_length)); |
| 29 | } |
| 30 | } |
| 31 | |